Skip to content

Commit

Permalink
Fix what I can (blocked by production issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Mar 30, 2023
1 parent 55c988d commit 928f739
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion qiskit/circuit/instructionset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
*,
Expand Down
16 changes: 8 additions & 8 deletions test/python/circuit/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -583,30 +583,30 @@ 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])
for i, bit in enumerate(bits):
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)

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: .*"
Expand All @@ -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: .*"
Expand All @@ -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)
Expand Down
30 changes: 17 additions & 13 deletions test/python/visualization/timeline/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 928f739

Please sign in to comment.