Skip to content

Commit

Permalink
update deprecated code (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrijapau authored Nov 14, 2024
1 parent 0122cce commit f1ac194
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
20 changes: 13 additions & 7 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,10 +2098,13 @@ def ansatz_false():
qml.Barrier([0, 1, 2])
return [qml.expval(m) for m in [m0, m1, qml.measure(0), qml.measure(1), qml.measure(2)]]

loaded_qiskit_circuit_tape = qml.workflow.construct_tape(loaded_qiskit_circuit)()
built_pl_circuit_tape = qml.workflow.construct_tape(built_pl_circuit)()

assert loaded_qiskit_circuit() == built_pl_circuit()
assert len(loaded_qiskit_circuit.tape.operations) == len(built_pl_circuit.tape.operations)
assert len(loaded_qiskit_circuit_tape.operations) == len(built_pl_circuit_tape.operations)
for op1, op2 in zip(
loaded_qiskit_circuit.tape.operations, built_pl_circuit.tape.operations
loaded_qiskit_circuit_tape.operations, built_pl_circuit_tape.operations
):
if isinstance(op1, MidMeasureMP) or isinstance(op2, MidMeasureMP):
assert op1.wires == op2.wires
Expand Down Expand Up @@ -2187,11 +2190,12 @@ def built_pl_circuit():

return qml.expval(qml.PauliZ(0) @ qml.PauliY(1))

loaded_qiskit_circuit_tape = qml.workflow.construct_tape(loaded_qiskit_circuit)()
built_pl_circuit_tape = qml.workflow.construct_tape(built_pl_circuit)()
assert loaded_qiskit_circuit() == built_pl_circuit()

assert len(loaded_qiskit_circuit.tape.operations) == len(built_pl_circuit.tape.operations)
assert len(loaded_qiskit_circuit_tape.operations) == len(built_pl_circuit_tape.operations)
for op1, op2 in zip(
loaded_qiskit_circuit.tape.operations, built_pl_circuit.tape.operations
loaded_qiskit_circuit_tape.operations, built_pl_circuit_tape.operations
):
if isinstance(op1, MidMeasureMP) or isinstance(op2, MidMeasureMP):
assert op1.wires == op2.wires
Expand Down Expand Up @@ -2285,9 +2289,11 @@ def pl_circuit():
qml.cond(m1 == 1, qml.PauliX)(wires=[2])
return qml.expval(qml.PauliZ(0))

qk_circuit_tape = qml.workflow.construct_tape(qk_circuit)()
pl_circuit_tape = qml.workflow.construct_tape(pl_circuit)()
assert qk_circuit() == pl_circuit()
assert len(qk_circuit.tape.operations) == len(pl_circuit.tape.operations)
for op1, op2 in zip(qk_circuit.tape.operations, pl_circuit.tape.operations):
assert len(qk_circuit_tape.operations) == len(pl_circuit_tape.operations)
for op1, op2 in zip(qk_circuit_tape.operations, pl_circuit_tape.operations):
if isinstance(op1, MidMeasureMP) or isinstance(op2, MidMeasureMP):
assert op1.wires == op2.wires
elif isinstance(op1, qml.ops.Conditional) or isinstance(op2, qml.ops.Conditional):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ def circuit(phi=None):
return qml.expval(qml.PauliZ(0))

phi = tensor([[0.04439891, 0.14490549, 3.29725643, 2.51240058]])
circuit(phi)
ops = circuit.tape.operations
tape = qml.workflow.construct_tape(circuit)(phi)
ops = tape.operations
for i in range(phi.shape[1]):
# Test each rotation applied
assert ops[i].name == "RX"
Expand All @@ -469,8 +469,8 @@ def circuit(phi=None):

phi = tensor([[0.04439891, 0.14490549, 3.29725643]])

circuit(phi)
ops = circuit.tape.operations
tape = qml.workflow.construct_tape(circuit)(phi)
ops = tape.operations
# Test the rotation applied
assert ops[0].name == "Rot"
assert len(ops[0].parameters) == 3
Expand Down
5 changes: 3 additions & 2 deletions tests/test_qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,6 @@ def barrier_func():
return qml.state()

res = barrier_func()
assert barrier_func.tape.operations[0] == qml.Barrier([0, 1])
assert np.allclose(res, dev.batch_execute([barrier_func.tape]), atol=0)
tape = qml.workflow.construct_tape(barrier_func)()
assert tape.operations[0] == qml.Barrier([0, 1])
assert np.allclose(res, dev.batch_execute([tape]), atol=0)

0 comments on commit f1ac194

Please sign in to comment.