adjust controlledcircuit.py to qiskit terra 0.8
@@ -42,7 +42,10 @@ def apply_cu3(circuit, theta, phi, lam, c, t, use_basis_gates=True):
circuit.u3(theta / 2, phi, 0, t)
else:
circuit.cu3(theta, phi, lam, c, t)
+
# the u3 gate below is added to account for qiskit terra's cu3
+ # TODO: here or only in if=True clause?
+ if not np.isclose(float(phi + lam), 0.0):
circuit.u3(0, 0, (phi + lam) / 2, c)
@@ -112,18 +115,18 @@ def get_controlled_circuit(circuit, ctl_qubit, tgt_circuit=None, use_basis_gates
if not qc.has_register(ctl_qubit[0]):
qc.add(ctl_qubit[0])
for op in ops:
- if op.name == 'id':
- apply_cu3(qc, 0, 0, 0, ctl_qubit, op.qargs[0], use_basis_gates=use_basis_gates)
- elif op.name == 'u1':
- apply_cu1(qc, *op.params, ctl_qubit, op.qargs[0], use_basis_gates=use_basis_gates)
- elif op.name == 'u2':
- apply_cu3(qc, np.pi / 2, *op.params, ctl_qubit, op.qargs[0], use_basis_gates=use_basis_gates)
- elif op.name == 'u3':
- apply_cu3(qc, *op.params, ctl_qubit, op.qargs[0], use_basis_gates=use_basis_gates)
- elif op.name == 'cx':
- apply_ccx(qc, ctl_qubit, *op.qargs, use_basis_gates=use_basis_gates)
- elif op.name == 'measure':
- qc.measure(op.qargs[0], op.cargs[0])
+ if op[0].name == 'id':
+ apply_cu3(qc, 0, 0, 0, ctl_qubit, op[1][0], use_basis_gates=use_basis_gates)
+ elif op[0].name == 'u1':
+ apply_cu1(qc, *op[0].params, ctl_qubit, op[1][0], use_basis_gates=use_basis_gates)
+ elif op[0].name == 'u2':
+ apply_cu3(qc, np.pi / 2, *op[0].params, ctl_qubit, op[1][0], use_basis_gates=use_basis_gates)
+ elif op[0].name == 'u3':
+ apply_cu3(qc, *op[0].params, ctl_qubit, op[1][0], use_basis_gates=use_basis_gates)
+ elif op[0].name == 'cx':
+ apply_ccx(qc, ctl_qubit, *op[1], use_basis_gates=use_basis_gates)
+ elif op[0].name == 'measure':
+ qc.measure(op[1], op[2])
else:
raise RuntimeError('Unexpected operation {}.'.format(op['name']))
