def test_initialize_reset_should_be_removed(self): """The reset in front of initializer should be removed when zero state""" qr = QuantumRegister(1, "qr") qc = QuantumCircuit(qr) qc.initialize([1.0 / math.sqrt(2), 1.0 / math.sqrt(2)], [qr[0]]) qc.initialize([1.0 / math.sqrt(2), -1.0 / math.sqrt(2)], [qr[0]]) expected = QuantumCircuit(qr) expected.append(U3Gate(1.5708, 0, 0), [qr[0]]) expected.reset(qr[0]) expected.append(U3Gate(1.5708, 3.1416, 0), [qr[0]]) after = transpile(qc, basis_gates=['reset', 'u3'], optimization_level=1) self.assertEqual(after, expected)
def test_unroll_rzz(self): """test unroll rzz""" self.circuit.rzz(0.6, 1, 0) self.ref_circuit.cx(1, 0) self.ref_circuit.append(U3Gate(0, 0, 0.6), [0]) self.ref_circuit.cx(1, 0) self.compare_dags()
def test_3q_schedule(self): """Test a schedule that was recommended by David McKay :D""" # ┌─────────────────┐ # q0_0: ─────────■─────────┤ U3(3.14,1.57,0) ├──────────────────────── # ┌─┴─┐ └┬───────────────┬┘ # q0_1: ───────┤ X ├────────┤ U2(3.14,1.57) ├───■───────────────────── # ┌──────┴───┴──────┐ └───────────────┘ ┌─┴─┐┌─────────────────┐ # q0_2: ┤ U2(0.778,0.122) ├───────────────────┤ X ├┤ U2(0.778,0.122) ├ # └─────────────────┘ └───┘└─────────────────┘ backend = FakeOpenPulse3Q() inst_map = backend.defaults().instruction_schedule_map q = QuantumRegister(3) c = ClassicalRegister(3) qc = QuantumCircuit(q, c) qc.cx(q[0], q[1]) qc.append(U2Gate(0.778, 0.122), [q[2]]) qc.append(U3Gate(3.14, 1.57, 0), [q[0]]) qc.append(U2Gate(3.14, 1.57), [q[1]]) qc.cx(q[1], q[2]) qc.append(U2Gate(0.778, 0.122), [q[2]]) sched = schedule(qc, backend) expected = Schedule( inst_map.get("cx", [0, 1]), (22, inst_map.get("u2", [1], 3.14, 1.57)), (22, inst_map.get("u2", [2], 0.778, 0.122)), (24, inst_map.get("cx", [1, 2])), (44, inst_map.get("u3", [0], 3.14, 1.57, 0)), (46, inst_map.get("u2", [2], 0.778, 0.122)), ) for actual, expected in zip(sched.instructions, expected.instructions): self.assertEqual(actual[0], expected[0]) self.assertEqual(actual[1], expected[1])
def test_complex_1_qubit_circuit(self): q = QuantumRegister(1) circ = QuantumCircuit(q) circ.append(U3Gate(1, 1, 1), [q[0]]) rho, psi = run_circuit_and_tomography(circ, q, self.method) F_bell = state_fidelity(psi, rho, validate=False) self.assertAlmostEqual(F_bell, 1, places=1)
def make_hard_thetas_oneq(smallest=1e-18, factor=3.2, steps=22, phi=0.7, lam=0.9): """Make 1q gates with theta/2 close to 0, pi/2, pi, 3pi/2""" return ([U3Gate(smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(-smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(np.pi / 2 + smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(np.pi / 2 - smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(np.pi + smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(np.pi - smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(3 * np.pi / 2 + smallest * factor ** i, phi, lam) for i in range(steps)] + [U3Gate(3 * np.pi / 2 - smallest * factor ** i, phi, lam) for i in range(steps)])
def test_layout_2503(self, level): """Test that a user-given initial layout is respected, even if cnots are not in the coupling map. See: https://github.com/Qiskit/qiskit-terra/issues/2503 """ # build a circuit which works as-is on the coupling map, using the initial layout qr = QuantumRegister(3, "q") cr = ClassicalRegister(2) ancilla = QuantumRegister(17, "ancilla") qc = QuantumCircuit(qr, cr) qc.append(U3Gate(0.1, 0.2, 0.3), [qr[0]]) qc.append(U2Gate(0.4, 0.5), [qr[2]]) qc.barrier() qc.cx(qr[0], qr[2]) initial_layout = [6, 7, 12] final_layout = { 0: ancilla[0], 1: ancilla[1], 2: ancilla[2], 3: ancilla[3], 4: ancilla[4], 5: ancilla[5], 6: qr[0], 7: qr[1], 8: ancilla[6], 9: ancilla[7], 10: ancilla[8], 11: ancilla[9], 12: qr[2], 13: ancilla[10], 14: ancilla[11], 15: ancilla[12], 16: ancilla[13], 17: ancilla[14], 18: ancilla[15], 19: ancilla[16], } backend = FakePoughkeepsie() qc_b = transpile(qc, backend, initial_layout=initial_layout, optimization_level=level) self.assertEqual(qc_b._layout._p2v, final_layout) gate_0, qubits_0, _ = qc_b[0] gate_1, qubits_1, _ = qc_b[1] output_qr = qc_b.qregs[0] self.assertIsInstance(gate_0, U3Gate) self.assertEqual(qubits_0[0], output_qr[6]) self.assertIsInstance(gate_1, U2Gate) self.assertEqual(qubits_1[0], output_qr[12])
def test_loading_all_qelib1_gates(self): """Test setting up a circuit with all gates defined in qiskit/qasm/libs/qelib1.inc.""" from qiskit.circuit.library import U1Gate, U2Gate, U3Gate, CU1Gate, CU3Gate, UGate all_gates_qasm = os.path.join(self.qasm_dir, "all_gates.qasm") qasm_circuit = QuantumCircuit.from_qasm_file(all_gates_qasm) ref_circuit = QuantumCircuit(3, 3) # abstract gates (legacy) ref_circuit.append(UGate(0.2, 0.1, 0.6), [0]) ref_circuit.cx(0, 1) # the hardware primitives ref_circuit.append(U3Gate(0.2, 0.1, 0.6), [0]) ref_circuit.append(U2Gate(0.1, 0.6), [0]) ref_circuit.append(U1Gate(0.6), [0]) ref_circuit.id(0) ref_circuit.cx(0, 1) # the standard single qubit gates ref_circuit.u(0.2, 0.1, 0.6, 0) ref_circuit.p(0.6, 0) ref_circuit.x(0) ref_circuit.y(0) ref_circuit.z(0) ref_circuit.h(0) ref_circuit.s(0) ref_circuit.t(0) ref_circuit.sdg(0) ref_circuit.tdg(0) ref_circuit.sx(0) ref_circuit.sxdg(0) # the standard rotations ref_circuit.rx(0.1, 0) ref_circuit.ry(0.1, 0) ref_circuit.rz(0.1, 0) # the barrier ref_circuit.barrier() # the standard user-defined gates ref_circuit.swap(0, 1) ref_circuit.cswap(0, 1, 2) ref_circuit.cy(0, 1) ref_circuit.cz(0, 1) ref_circuit.ch(0, 1) ref_circuit.csx(0, 1) ref_circuit.append(CU1Gate(0.6), [0, 1]) ref_circuit.append(CU3Gate(0.2, 0.1, 0.6), [0, 1]) ref_circuit.cp(0.6, 0, 1) ref_circuit.cu(0.2, 0.1, 0.6, 0, 0, 1) ref_circuit.ccx(0, 1, 2) ref_circuit.crx(0.6, 0, 1) ref_circuit.cry(0.6, 0, 1) ref_circuit.crz(0.6, 0, 1) ref_circuit.rxx(0.2, 0, 1) ref_circuit.rzz(0.2, 0, 1) ref_circuit.measure([0, 1, 2], [0, 1, 2]) self.assertEqual(qasm_circuit, ref_circuit)
def test_optimize_u3_basis_u3(self): """U3(pi/2, pi/3, pi/4) (basis[u3]) -> U3(pi/2, pi/3, pi/4)""" qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr) circuit.append(U3Gate(np.pi / 2, np.pi / 3, np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(["u3"])) result = passmanager.run(circuit) self.assertEqual(circuit, result)
def generate_parameterized_circuit(): """Generate a circuit with parameters and parameter expressions.""" param_circuit = QuantumCircuit(1) theta = Parameter("theta") lam = Parameter("λ") theta_pi = 3.14159 * theta pe = theta_pi / lam param_circuit.append(U3Gate(theta, theta_pi, lam), [0]) param_circuit.append(U1Gate(pe), [0]) param_circuit.append(U2Gate(theta_pi, lam), [0]) return param_circuit
def test_optimize_u3_with_parameters(self): """Test correct behavior for u3 gates.""" phi = Parameter("φ") alpha = Parameter("α") qr = QuantumRegister(1, "qr") qc = QuantumCircuit(qr) qc.ry(2 * phi, qr[0]) qc.ry(alpha, qr[0]) qc.ry(0.1, qr[0]) qc.ry(0.2, qr[0]) passmanager = PassManager([Unroller(["u3"]), Optimize1qGates()]) result = passmanager.run(qc) expected = QuantumCircuit(qr) expected.append(U3Gate(2 * phi, 0, 0), [qr[0]]) expected.append(U3Gate(alpha, 0, 0), [qr[0]]) expected.append(U3Gate(0.3, 0, 0), [qr[0]]) self.assertEqual(expected, result)
def test_unroll_1q_chain_conditional(self): """Test unroll chain of 1-qubit gates interrupted by conditional. """ qr = QuantumRegister(1, 'qr') cr = ClassicalRegister(1, 'cr') circuit = QuantumCircuit(qr, cr) circuit.h(qr) circuit.tdg(qr) circuit.z(qr) circuit.t(qr) circuit.ry(0.5, qr) circuit.rz(0.3, qr) circuit.rx(0.1, qr) circuit.measure(qr, cr) circuit.x(qr).c_if(cr, 1) circuit.y(qr).c_if(cr, 1) circuit.z(qr).c_if(cr, 1) dag = circuit_to_dag(circuit) pass_ = UnrollCustomDefinitions(std_eqlib, ['u1', 'u2', 'u3']) dag = pass_.run(dag) pass_ = BasisTranslator(std_eqlib, ['u1', 'u2', 'u3']) unrolled_dag = pass_.run(dag) # Pick up -1 * 0.3 / 2 global phase for one RZ -> U1. ref_circuit = QuantumCircuit(qr, cr, global_phase=-0.3 / 2) ref_circuit.append(U2Gate(0, pi), [qr[0]]) ref_circuit.append(U1Gate(-pi / 4), [qr[0]]) ref_circuit.append(U1Gate(pi), [qr[0]]) ref_circuit.append(U1Gate(pi / 4), [qr[0]]) ref_circuit.append(U3Gate(0.5, 0, 0), [qr[0]]) ref_circuit.append(U1Gate(0.3), [qr[0]]) ref_circuit.append(U3Gate(0.1, -pi / 2, pi / 2), [qr[0]]) ref_circuit.measure(qr[0], cr[0]) ref_circuit.append(U3Gate(pi, 0, pi), [qr[0]]).c_if(cr, 1) ref_circuit.append(U3Gate(pi, pi / 2, pi / 2), [qr[0]]).c_if(cr, 1) ref_circuit.append(U1Gate(pi), [qr[0]]).c_if(cr, 1) ref_dag = circuit_to_dag(ref_circuit) self.assertEqual(unrolled_dag, ref_dag)
def test_complex_3_qubit_circuit(self): def rand_angles(): # pylint: disable=E1101 return tuple(2 * numpy.pi * numpy.random.random(3) - numpy.pi) q = QuantumRegister(3) circ = QuantumCircuit(q) for j in range(3): circ.append(U3Gate(*rand_angles()), [q[j]]) rho, psi = run_circuit_and_tomography(circ, q, self.method) F_bell = state_fidelity(psi, rho, validate=False) self.assertAlmostEqual(F_bell, 1, places=1)
def test_unroller_one(self): """Test unrolling gate.repeat(1). """ qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr) circuit.append(SGate().repeat(1), [qr[0]]) result = PassManager(Unroller('u3')).run(circuit) expected = QuantumCircuit(qr) expected.append(U3Gate(0, 0, pi / 2), [qr[0]]) self.assertEqual(result, expected)
def test_unroll_rzz(self): """test unroll rzz""" # global phase: 5.9832 # ┌───┐┌─────────────┐┌───┐ # qr_0: ─■──────── qr_0: ┤ X ├┤ U3(0,0,0.6) ├┤ X ├ # │ZZ(0.6) = └─┬─┘└─────────────┘└─┬─┘ # qr_1: ─■──────── qr_1: ──■───────────────────■── self.circuit.rzz(0.6, 1, 0) self.ref_circuit.global_phase = -1 * 0.6 / 2 self.ref_circuit.cx(1, 0) self.ref_circuit.append(U3Gate(0, 0, 0.6), [0]) self.ref_circuit.cx(1, 0) self.compare_dags()
def test_global_phase_u3_on_left(self): """Check proper phase accumulation with instruction with no definition.""" qr = QuantumRegister(1) qc = QuantumCircuit(qr) u1 = U1Gate(0.1) u1.definition.global_phase = np.pi / 2 qc.append(u1, [0]) qc.global_phase = np.pi / 3 qc.append(U3Gate(0.1, 0.2, 0.3), [0]) dag = circuit_to_dag(qc) after = Optimize1qGates().run(dag) self.assertAlmostEqual(after.global_phase, 5 * np.pi / 6, 8)
def test_u_gates(self): """Test U 1, 2, & 3 gates""" from qiskit.circuit.library import U1Gate, U2Gate, U3Gate, CU1Gate, CU3Gate qr = QuantumRegister(4, 'q') circuit = QuantumCircuit(qr) circuit.append(U1Gate(3 * pi / 2), [0]) circuit.append(U2Gate(3 * pi / 2, 2 * pi / 3), [1]) circuit.append(U3Gate(3 * pi / 2, 4.5, pi / 4), [2]) circuit.append(CU1Gate(pi / 4), [0, 1]) circuit.append(U2Gate(pi / 2, 3 * pi / 2).control(1), [2, 3]) circuit.append(CU3Gate(3 * pi / 2, -3 * pi / 4, -pi / 2), [0, 1]) self.circuit_drawer(circuit, filename='u_gates.png')
class TestParameterCtrlState(QiskitTestCase): """Test gate equality with ctrl_state parameter.""" @data((RXGate(0.5), CRXGate(0.5)), (RYGate(0.5), CRYGate(0.5)), (RZGate(0.5), CRZGate(0.5)), (XGate(), CXGate()), (YGate(), CYGate()), (ZGate(), CZGate()), (U1Gate(0.5), CU1Gate(0.5)), (SwapGate(), CSwapGate()), (HGate(), CHGate()), (U3Gate(0.1, 0.2, 0.3), CU3Gate(0.1, 0.2, 0.3))) @unpack def test_ctrl_state_one(self, gate, controlled_gate): """Test controlled gates with ctrl_state See https://github.com/Qiskit/qiskit-terra/pull/4025 """ self.assertEqual(gate.control(1, ctrl_state='1'), controlled_gate)
def test_optimize_u1_basis_u2(self): """U1(pi/4) -> Raises. Basis [u2]""" qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr) circuit.append(U1Gate(np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(U3Gate(0, 0, np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(["u2"])) with self.assertRaises(TranspilerError): _ = passmanager.run(circuit)
def test_unroll_ccx(self): """test unroll ccx""" self.circuit.ccx(0, 1, 2) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) self.ref_circuit.cx(1, 2) self.ref_circuit.append(U3Gate(0, 0, -pi / 4), [2]) self.ref_circuit.cx(0, 2) self.ref_circuit.append(U3Gate(0, 0, pi / 4), [2]) self.ref_circuit.cx(1, 2) self.ref_circuit.append(U3Gate(0, 0, pi / 4), [1]) self.ref_circuit.append(U3Gate(0, 0, -pi / 4), [2]) self.ref_circuit.cx(0, 2) self.ref_circuit.cx(0, 1) self.ref_circuit.append(U3Gate(0, 0, pi / 4), [0]) self.ref_circuit.append(U3Gate(0, 0, -pi / 4), [1]) self.ref_circuit.cx(0, 1) self.ref_circuit.append(U3Gate(0, 0, pi / 4), [2]) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) self.compare_dags()
def test_optimize_u3_to_phase_gate(self): """U3(0, 0, pi/4) -> U1(pi/4)""" qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr) circuit.append(U3Gate(0, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(PhaseGate(np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(['p', 'u2', 'u', 'cx', 'id'])) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_optimize_u3_basis_u2(self): """U3(pi/2, 0, pi/4) -> U2(0, pi/4)""" qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr) circuit.append(U3Gate(np.pi / 2, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(U2Gate(0, np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(['u2'])) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_optimize_u3_basis_phase_gate(self): """U3(0, 0, pi/4) -> p(pi/4). Basis [p].""" qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) circuit.append(U3Gate(0, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(PhaseGate(np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(["p"])) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_optimize_u3_basis_u2_u1(self): """U3(pi/2, 0, pi/4) -> U2(0, pi/4). Basis [u2, u1].""" qr = QuantumRegister(2, "qr") circuit = QuantumCircuit(qr) circuit.append(U3Gate(np.pi / 2, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(U2Gate(0, np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(["u2", "u1"])) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_optimize_u1_basis_u2_u3(self): """U1(pi/4) -> U3(0, 0, pi/4). Basis [u2, u3].""" qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr) circuit.append(U1Gate(np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(U3Gate(0, 0, np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(['u2', 'u3'])) result = passmanager.run(circuit) self.assertEqual(expected, result)
def check_one_qubit_euler_angles(self, operator, tolerance=1e-14): """Check euler_angles_1q works for the given unitary""" with self.subTest(operator=operator): target_unitary = operator.data angles = euler_angles_1q(target_unitary) decomp_unitary = U3Gate(*angles).to_matrix() target_unitary *= la.det(target_unitary)**(-0.5) decomp_unitary *= la.det(decomp_unitary)**(-0.5) maxdist = np.max(np.abs(target_unitary - decomp_unitary)) if maxdist > 0.1: maxdist = np.max(np.abs(target_unitary + decomp_unitary)) self.assertTrue( np.abs(maxdist) < tolerance, "Worst distance {}".format(maxdist))
def test_optimize_u3_to_u1(self): """U3(0, 0, pi/4) -> U1(pi/4)""" qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr) circuit.append(U3Gate(0, 0, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(U1Gate(np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates()) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_optimize_u3_to_phase_round(self): """U3(1e-16, 1e-16, pi/4) -> U1(pi/4)""" qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr) circuit.append(U3Gate(1e-16, 1e-16, np.pi / 4), [qr[0]]) expected = QuantumCircuit(qr) expected.append(PhaseGate(np.pi / 4), [qr[0]]) passmanager = PassManager() passmanager.append(Optimize1qGates(["p", "u2", "u", "cx", "id"])) result = passmanager.run(circuit) self.assertEqual(expected, result)
def test_unroll_1q_chain_conditional(self): """Test unroll chain of 1-qubit gates interrupted by conditional. """ qr = QuantumRegister(1, 'qr') cr = ClassicalRegister(1, 'cr') circuit = QuantumCircuit(qr, cr) circuit.h(qr) circuit.tdg(qr) circuit.z(qr) circuit.t(qr) circuit.ry(0.5, qr) circuit.rz(0.3, qr) circuit.rx(0.1, qr) circuit.measure(qr, cr) circuit.x(qr).c_if(cr, 1) circuit.y(qr).c_if(cr, 1) circuit.z(qr).c_if(cr, 1) dag = circuit_to_dag(circuit) pass_ = Unroller(['u1', 'u2', 'u3']) unrolled_dag = pass_.run(dag) ref_circuit = QuantumCircuit(qr, cr) ref_circuit.append(U2Gate(0, pi), [qr[0]]) ref_circuit.append(U1Gate(-pi / 4), [qr[0]]) ref_circuit.append(U1Gate(pi), [qr[0]]) ref_circuit.append(U1Gate(pi / 4), [qr[0]]) ref_circuit.append(U3Gate(0.5, 0, 0), [qr[0]]) ref_circuit.append(U1Gate(0.3), [qr[0]]) ref_circuit.append(U3Gate(0.1, -pi / 2, pi / 2), [qr[0]]) ref_circuit.measure(qr[0], cr[0]) ref_circuit.append(U3Gate(pi, 0, pi), [qr[0]]).c_if(cr, 1) ref_circuit.append(U3Gate(pi, pi / 2, pi / 2), [qr[0]]).c_if(cr, 1) ref_circuit.append(U1Gate(pi), [qr[0]]).c_if(cr, 1) ref_dag = circuit_to_dag(ref_circuit) self.assertEqual(unrolled_dag, ref_dag)
def sicpovm_preparation_circuit(op: str, qubit: QuantumRegister) -> QuantumCircuit: """ Return a SIC-POVM projector preparation circuit. This circuit assumes the qubit is initialized in the :math:`Z_p` eigenstate :math:`[1, 0]`. Params: op: SIC-POVM element label 'S0', 'S1', 'S2' or 'S3'. qubit: qubit to be prepared. Returns: The preparation circuit """ circ = QuantumCircuit(qubit.register) theta = -2 * np.arctan(np.sqrt(2)) if op == 'S1': circ.append(U3Gate(theta, np.pi, 0.0), [qubit]) if op == 'S2': circ.append(U3Gate(theta, np.pi / 3, 0.0), [qubit]) if op == 'S3': circ.append(U3Gate(theta, -np.pi / 3, 0.0), [qubit]) return circ
def get_data_point(theta, phi, lam, readout_params, depol_param, thermal_params, shots): """Generate a dict datapoint with the given circuit and noise parameters""" U3_gate_length = 7.111111111111112e-08 circ = QuantumCircuit(1, 1) circ.append(U3Gate(theta, phi, lam), [0]) circ.measure(0, 0) new_circ = qiskit.compiler.transpile(circ, basis_gates=['u3'], optimization_level=0) # extract parameters (p0_0, p1_0), (p0_1, p1_1) = readout_params depol_prob = depol_param t1, t2, population = thermal_params noise_model = NoiseModel() # Add Readout and Quantum Errors noise_model.add_all_qubit_readout_error(ReadoutError(readout_params)) noise_model.add_all_qubit_quantum_error(depolarizing_error(depol_param, 1), 'u3', warnings=False) noise_model.add_all_qubit_quantum_error(thermal_relaxation_error( t1, t2, U3_gate_length, population), 'u3', warnings=False) job = execute(circ, QasmSimulator(), shots=shots, noise_model=noise_model) result = job.result() # add data point to DataFrame data_point = { 'theta': theta, 'phi': phi, 'lam': lam, 'p0_0': p0_0, 'p1_0': p1_0, 'p0_1': p0_1, 'p1_1': p1_1, 'depol_prob': depol_prob, 't1': t1, 't2': t2, 'population': population, 'E': result.get_counts(0).get('0', 0) / shots } return data_point