From 928f73933cba75efdc2612331c26ad476d10d596 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Thu, 30 Mar 2023 07:09:58 -0600 Subject: [PATCH] Fix what I can (blocked by production issues) --- qiskit/circuit/instructionset.py | 2 +- test/python/circuit/test_instructions.py | 16 +++++----- .../visualization/timeline/test_generators.py | 30 +++++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/qiskit/circuit/instructionset.py b/qiskit/circuit/instructionset.py index 10c0653caf01..d4bfefa595dc 100644 --- a/qiskit/circuit/instructionset.py +++ b/qiskit/circuit/instructionset.py @@ -105,7 +105,7 @@ class InstructionSet: "indices to be resolved incorrectly if any registers overlap.)" ), ) - def __init__( + def __init__( # pylint: disable=bad-docstring-quotes self, circuit_cregs: list[ClassicalRegister] | None = None, *, diff --git a/test/python/circuit/test_instructions.py b/test/python/circuit/test_instructions.py index 95466917d9f1..d1170f7c9d8d 100644 --- a/test/python/circuit/test_instructions.py +++ b/test/python/circuit/test_instructions.py @@ -568,7 +568,7 @@ def test_instructionset_c_if_deprecated_resolution(self): registers = [ClassicalRegister(2), ClassicalRegister(3), ClassicalRegister(1)] bits = [bit for register in registers for bit in register] - deprecated_regex = r"The 'circuit_cregs' argument to 'InstructionSet' is deprecated .*" + deprecated_regex = r".* argument ``circuit_cregs`` is deprecated .*" def dummy_requester(specifier): """A dummy requester that technically fulfills the spec.""" @@ -583,14 +583,14 @@ def dummy_requester(specifier): with self.subTest("classical register"): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) instructions.c_if(registers[0], 0) self.assertIs(instruction.condition[0], registers[0]) with self.subTest("classical bit"): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) instructions.c_if(registers[0][1], 0) self.assertIs(instruction.condition[0], registers[0][1]) @@ -598,7 +598,7 @@ def dummy_requester(specifier): with self.subTest("bit index", index=i): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) instructions.c_if(i, 0) self.assertIs(instruction.condition[0], bit) @@ -606,7 +606,7 @@ def dummy_requester(specifier): with self.subTest("raises on bad register"): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) with self.assertRaisesRegex( CircuitError, r"Condition register .* is not one of the registers known here: .*" @@ -615,7 +615,7 @@ def dummy_requester(specifier): with self.subTest("raises on bad bit"): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) with self.assertRaisesRegex( CircuitError, "Condition bit .* is not in the registers known here: .*" @@ -624,14 +624,14 @@ def dummy_requester(specifier): with self.subTest("raises on bad index"): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) with self.assertRaisesRegex(CircuitError, r"Bit index .* is out-of-range\."): instructions.c_if(len(bits), 0) with self.subTest("raises on bad type"): instruction = HGate() with self.assertWarnsRegex(DeprecationWarning, deprecated_regex): - instructions = InstructionSet(registers) + instructions = InstructionSet(circuit_cregs=registers) instructions.add(instruction, [Qubit()], []) with self.assertRaisesRegex(CircuitError, r"Invalid classical condition\. .*"): instructions.c_if([0], 0) diff --git a/test/python/visualization/timeline/test_generators.py b/test/python/visualization/timeline/test_generators.py index 7089bbc618d1..a8b976107759 100644 --- a/test/python/visualization/timeline/test_generators.py +++ b/test/python/visualization/timeline/test_generators.py @@ -55,15 +55,17 @@ def test_gen_sched_gate_with_finite_duration(self): [-0.5 * self.formatter["box_height.gate"], 0.5 * self.formatter["box_height.gate"]], ) self.assertListEqual(drawing_obj.bits, [self.qubit]) - ref_meta = { - "name": "u3", - "label": "n/a", - "bits": str(self.qubit.register.name), - "t0": 100, - "duration": 20, - "unitary": "[[1.+0.j 0.-0.j]\n [0.+0.j 1.+0.j]]", - "parameters": "0, 0, 0", - } + # TODO: rewrite this to not use the deprecated `register` property. + with self.assertWarns(DeprecationWarning): + ref_meta = { + "name": "u3", + "label": "n/a", + "bits": str(self.qubit.register.name), + "t0": 100, + "duration": 20, + "unitary": "[[1.+0.j 0.-0.j]\n [0.+0.j 1.+0.j]]", + "parameters": "0, 0, 0", + } self.assertDictEqual(ref_meta, drawing_obj.meta) ref_styles = { @@ -244,10 +246,12 @@ def test_gen_bit_name(self): self.assertListEqual(list(drawing_obj.xvals), [types.AbstractCoordinate.LEFT]) self.assertListEqual(list(drawing_obj.yvals), [0]) self.assertListEqual(drawing_obj.bits, [self.qubit]) - self.assertEqual(drawing_obj.text, str(self.qubit.register.name)) - ref_latex = r"{{\rm {register}}}_{{{index}}}".format( - register=self.qubit.register.prefix, index=self.qubit.index - ) + # TODO: rewrite this to not use the deprecated `register` property. + with self.assertWarns(DeprecationWarning): + self.assertEqual(drawing_obj.text, str(self.qubit.register.name)) + ref_latex = r"{{\rm {register}}}_{{{index}}}".format( + register=self.qubit.register.prefix, index=self.qubit.index + ) self.assertEqual(drawing_obj.latex, ref_latex) ref_styles = {