def test_swap_gate_deterministic_minimal_basis_gates(self): """Test swap-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.swap_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_deterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates=['u3', 'cx']) result = job.result() self.assertTrue(getattr(result, 'success', False)) self.compare_unitary(result, circuits, targets)
def test_h_gate_nondeterministic_minimal_basis_gates(self): """Test h-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.h_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_nondeterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates=['u3', 'cx']) result = job.result() self.is_completed(result) self.compare_unitary(result, circuits, targets)
def test_sdg_gate_nondeterministic_waltz_basis_gates(self): """Test sdg-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.sdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_nondeterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates=['u1', 'u2', 'u3', 'cx']) result = job.result() self.assertTrue(getattr(result, 'success', False)) self.compare_unitary(result, circuits, targets)
def test_ccx_gate_nondeterministic_minimal_basis_gates(self): """Test ccx-gate gate circuits compiling to U,CX""" circuits = ref_non_clifford.ccx_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_nondeterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates='U,CX') result = job.result() self.is_completed(result) self.compare_unitary(result, circuits, targets)
def test_ccx_gate_deterministic_waltz_basis_gates(self): """Test ccx-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.ccx_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_deterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates=['u1', 'u2', 'u3', 'cx']) result = job.result() self.is_completed(result) self.compare_unitary(result, circuits, targets)
def test_swap_gate_nondeterministic_waltz_basis_gates(self): """Test swap-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.swap_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_nondeterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates='u1,u2,u3,cx') result = job.result() self.is_completed(result) self.compare_unitary(result, circuits, targets)
def test_y_gate_deterministic_minimal_basis_gates(self): """Test y-gate gate circuits compiling to U,CX DISABLED until transpiler bug is fixed. """ circuits = ref_1q_clifford.y_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.y_gate_unitary_deterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates=['u3', 'cx']) result = job.result() self.is_completed(result) self.compare_unitary(result, circuits, targets)
class UnitarySaveUnitaryTests: """QasmSimulator SaveStatevector instruction tests.""" SIMULATOR = UnitarySimulator() BACKEND_OPTS = {} def test_save_unitary(self): """Test save unitary for instruction""" SUPPORTED_METHODS = [ 'automatic', 'unitary', 'unitary_gpu', 'unitary_thrust' ] # Stabilizer test circuit circ = transpile(QuantumVolume(3), self.SIMULATOR) # Target unitary target = qi.Operator(circ) # Add save to circuit save_key = 'state' circ.save_unitary(save_key) # Run opts = self.BACKEND_OPTS.copy() qobj = assemble(circ, self.SIMULATOR) result = self.SIMULATOR.run(qobj, **opts).result() method = opts.get('method', 'automatic') if method not in SUPPORTED_METHODS: self.assertFalse(result.success) else: self.assertTrue(result.success) data = result.data(0) self.assertIn(save_key, data) value = qi.Operator(result.data(0)[save_key]) self.assertEqual(value, target)
assert result.success is True # Run statevector simulator circuits = cx_gate_circuits_deterministic(final_measure=False) targets = cx_gate_statevector_deterministic() job = execute(circuits, StatevectorSimulator(), shots=1) result = job.result() assert result.status == 'COMPLETED' assert result.success is True compare_statevector(result, circuits, targets) # Run unitary simulator circuits = cx_gate_circuits_deterministic(final_measure=False) targets = cx_gate_unitary_deterministic() job = execute(circuits, UnitarySimulator(), shots=1, basis_gates=['u1', 'u2', 'u3', 'cx']) result = job.result() assert result.status == 'COMPLETED' assert result.success is True compare_unitary(result, circuits, targets) # Run pulse simulator system_model, schedule = model_and_pi_schedule() backend_sim = PulseSimulator() qobj = assemble([schedule], backend=backend_sim, qubit_lo_freq=[5.0], meas_level=1, meas_return='avg',
class UnitaryGateTests: """UnitarySimulator circuit library standard gate tests.""" SIMULATOR = UnitarySimulator() BACKEND_OPTS = {} SEED = 8181 RNG = default_rng(seed=SEED) GATES = [ # Clifford Gates (CXGate, 0), (CYGate, 0), (CZGate, 0), (DCXGate, 0), (HGate, 0), (IGate, 0), (SGate, 0), (SXGate, 0), (SXdgGate, 0), (SdgGate, 0), (SwapGate, 0), (XGate, 0), (YGate, 0), (ZGate, 0), (TGate, 0), # Non-Clifford Gates (TdgGate, 0), (iSwapGate, 0), (C3XGate, 0), (C4XGate, 0), (CCXGate, 0), (CHGate, 0), (CSXGate, 0), (CSwapGate, 0), # Parameterized Gates (CPhaseGate, 1), (CRXGate, 1), (CRYGate, 1), (CRZGate, 1), (CU1Gate, 1), (CU3Gate, 3), (CUGate, 4), (PhaseGate, 1), (RC3XGate, 1), (RCCXGate, 1), (RGate, 2), (RXGate, 1), (RXXGate, 1), (RYGate, 1), (RYYGate, 1), (RZGate, 1), (RZXGate, 1), (RZZGate, 1), (U1Gate, 1), (U2Gate, 2), (U3Gate, 3), (UGate, 3) ] BASIS_GATES = [ None, ['id', 'u1', 'u2', 'u3', 'cx'], ['id', 'u', 'cx'], ['id', 'r', 'cz'], ['id', 'rz', 'rx', 'cz'], ['id', 'p', 'sx', 'cx'] ] @data(*[(gate_params[0], gate_params[1], basis_gates) for gate_params, basis_gates in product(GATES, BASIS_GATES)]) @unpack def test_gate(self, gate_cls, num_params, basis_gates): """Test standard gate simulation.""" circuit = self.gate_circuit(gate_cls, num_params=num_params, rng=self.RNG) target = Operator(circuit) result = execute(circuit, self.SIMULATOR, basis_gates=basis_gates).result() self.assertSuccess(result) value = Operator(result.get_unitary(0)) self.assertTrue(target.equiv(value), msg='{}, basis_gates = {}'.format( gate_cls.__name__, basis_gates))
class UnitarySimulatorTests: """UnitarySimulator tests.""" SIMULATOR = UnitarySimulator() BACKEND_OPTS = {} # --------------------------------------------------------------------- # Test unitary gate qobj instruction # --------------------------------------------------------------------- def test_unitary_gate(self): """Test simulation with unitary gate circuit instructions.""" circuits = ref_unitary_gate.unitary_gate_circuits_deterministic( final_measure=False) targets = ref_unitary_gate.unitary_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_unitary_gate_circuit_run(self): """Test simulation with unitary gate circuit instructions.""" circuits = ref_unitary_gate.unitary_gate_circuits_deterministic( final_measure=False) targets = ref_unitary_gate.unitary_gate_unitary_deterministic() tqc = transpile(circuits, self.SIMULATOR) job = self.SIMULATOR.run(tqc, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_diagonal_gate(self): """Test simulation with diagonal gate circuit instructions.""" circuits = ref_diagonal_gate.diagonal_gate_circuits_deterministic( final_measure=False) targets = ref_diagonal_gate.diagonal_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test global phase # --------------------------------------------------------------------- def test_qobj_global_phase(self): """Test qobj global phase.""" circuits = ref_1q_clifford.h_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_nondeterministic() qobj = assemble(transpile(circuits, self.SIMULATOR), shots=1, **self.BACKEND_OPTS) # Set global phases for i, _ in enumerate(circuits): global_phase = (-1)**i * (pi / 4) qobj.experiments[i].header.global_phase = global_phase targets[i] = exp(1j * global_phase) * targets[i] result = self.SIMULATOR.run(qobj).result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets, ignore_phase=False)
class UnitaryFusionTests: """UnitarySimulator fusion tests.""" SIMULATOR = UnitarySimulator() def fusion_options(self, enabled=None, threshold=None, verbose=None): """Return default backend_options dict.""" backend_options = self.BACKEND_OPTS.copy() if enabled is not None: backend_options['fusion_enable'] = enabled if verbose is not None: backend_options['fusion_verbose'] = verbose if threshold is not None: backend_options['fusion_threshold'] = threshold return backend_options def fusion_metadata(self, result): """Return fusion metadata dict""" metadata = result.results[0].metadata return metadata.get('fusion', {}) def test_fusion_theshold(self): """Test fusion threhsold settings work.""" seed = 12345 threshold = 4 backend_options = self.fusion_options(enabled=True, threshold=threshold) with self.subTest(msg='below fusion threshold'): circuit = QuantumVolume(threshold - 1, seed=seed) circuit = transpile(circuit, self.SIMULATOR) qobj = assemble([circuit], shots=1) result = self.SIMULATOR.run( qobj, backend_options=backend_options).result() meta = self.fusion_metadata(result) self.assertSuccess(result) self.assertFalse(meta.get('applied')) with self.subTest(msg='at fusion threshold'): circuit = QuantumVolume(threshold, seed=seed) circuit = transpile(circuit, self.SIMULATOR) qobj = assemble([circuit], shots=1) result = self.SIMULATOR.run( qobj, backend_options=backend_options).result() meta = self.fusion_metadata(result) self.assertSuccess(result) self.assertTrue(meta.get('applied')) with self.subTest(msg='above fusion threshold'): circuit = QuantumVolume(threshold + 1, seed=seed) circuit = transpile(circuit, self.SIMULATOR) qobj = assemble([circuit], shots=1) result = self.SIMULATOR.run( qobj, backend_options=backend_options).result() meta = self.fusion_metadata(result) self.assertSuccess(result) self.assertTrue(meta.get('applied')) def test_fusion_disable(self): """Test Fusion enable/disable option""" seed = 2233 circuit = QuantumVolume(4, seed=seed) circuit = transpile(circuit, self.SIMULATOR) qobj = assemble([circuit], shots=1) with self.subTest(msg='test fusion enable'): backend_options = self.fusion_options(enabled=True, threshold=1) result = self.SIMULATOR.run( qobj, backend_options=backend_options).result() meta = self.fusion_metadata(result) self.assertSuccess(result) self.assertTrue(meta.get('applied')) with self.subTest(msg='test fusion disable'): backend_options = self.fusion_options(enabled=False, threshold=1) result = self.SIMULATOR.run( qobj, backend_options=backend_options).result() meta = self.fusion_metadata(result) self.assertSuccess(result) self.assertFalse(meta.get('applied')) def test_fusion_output(self): """Test Fusion returns same final unitary""" seed = 54321 circuit = QuantumVolume(4, seed=seed) circuit = transpile(circuit, self.SIMULATOR) qobj = assemble([circuit], shots=1) options_disabled = self.fusion_options(enabled=False, threshold=1) result_disabled = self.SIMULATOR.run( qobj, backend_options=options_disabled).result() self.assertSuccess(result_disabled) options_enabled = self.fusion_options(enabled=True, threshold=1) result_enabled = self.SIMULATOR.run( qobj, backend_options=options_enabled).result() self.assertSuccess(result_enabled) unitary_no_fusion = Operator(result_disabled.get_unitary(0)) unitary_fusion = Operator(result_enabled.get_unitary(0)) self.assertEqual(unitary_no_fusion, unitary_fusion)
assert result.success is True compare_counts(result, circuits, targets, delta=0.05 * shots) # Run statevector simulator circuits = cx_gate_circuits_deterministic(final_measure=False) targets = cx_gate_statevector_deterministic() backend = StatevectorSimulator() result = backend.run(transpile(circuits, backend), shots=1).result() assert result.status == 'COMPLETED' assert result.success is True compare_statevector(result, circuits, targets) # Run unitary simulator circuits = cx_gate_circuits_deterministic(final_measure=False) targets = cx_gate_unitary_deterministic() backend = UnitarySimulator() result = backend.run(transpile(circuits, backend), shots=1).result() assert result.status == 'COMPLETED' assert result.success is True compare_unitary(result, circuits, targets) # Run pulse simulator system_model, schedule = model_and_pi_schedule() backend_sim = PulseSimulator() qobj = assemble([schedule], backend=backend_sim, qubit_lo_freq=[5.0], meas_level=1, meas_return='avg', shots=1) results = backend_sim.run(qobj, system_model=system_model).result()
class UnitarySimulatorTests: """UnitarySimulator tests.""" SIMULATOR = UnitarySimulator() BACKEND_OPTS = {} # --------------------------------------------------------------------- # Test h-gate # --------------------------------------------------------------------- def test_h_gate_deterministic_default_basis_gates(self): """Test h-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.h_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_h_gate_deterministic_waltz_basis_gates(self): """Test h-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.h_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_h_gate_deterministic_minimal_basis_gates(self): """Test h-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.h_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_h_gate_nondeterministic_default_basis_gates(self): """Test h-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.h_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_h_gate_nondeterministic_waltz_basis_gates(self): """Test h-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.h_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_h_gate_nondeterministic_minimal_basis_gates(self): """Test h-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.h_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test x-gate # --------------------------------------------------------------------- def test_x_gate_deterministic_default_basis_gates(self): """Test x-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.x_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.x_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_x_gate_deterministic_waltz_basis_gates(self): """Test x-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.x_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.x_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_x_gate_deterministic_minimal_basis_gates(self): """Test x-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.x_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.x_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test z-gate # --------------------------------------------------------------------- def test_z_gate_deterministic_default_basis_gates(self): """Test z-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.z_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.z_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_z_gate_deterministic_waltz_basis_gates(self): """Test z-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.z_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.z_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_z_gate_deterministic_minimal_basis_gates(self): """Test z-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.z_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.z_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test y-gate # --------------------------------------------------------------------- def test_y_gate_deterministic_default_basis_gates(self): """Test y-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.y_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.y_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_y_gate_deterministic_waltz_basis_gates(self): """Test y-gate gate circuits compiling to u1,u2,u3,cx.""" circuits = ref_1q_clifford.y_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.y_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_y_gate_deterministic_minimal_basis_gates(self): """Test y-gate gate circuits compiling to u3, cx.""" circuits = ref_1q_clifford.y_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.y_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test s-gate # --------------------------------------------------------------------- def test_s_gate_deterministic_default_basis_gates(self): """Test s-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.s_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.s_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_s_gate_deterministic_waltz_basis_gates(self): """Test s-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.s_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.s_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_s_gate_deterministic_minimal_basis_gates(self): """Test s-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.s_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.s_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_s_gate_nondeterministic_default_basis_gates(self): """Test s-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.s_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.s_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_s_gate_nondeterministic_waltz_basis_gates(self): """Test s-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.s_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.s_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_s_gate_nondeterministic_minimal_basis_gates(self): """Test s-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.s_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.s_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test sdg-gate # --------------------------------------------------------------------- def test_sdg_gate_deterministic_default_basis_gates(self): """Test sdg-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.sdg_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_sdg_gate_deterministic_waltz_basis_gates(self): """Test sdg-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.sdg_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_sdg_gate_deterministic_minimal_basis_gates(self): """Test sdg-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.sdg_gate_circuits_deterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_sdg_gate_nondeterministic_default_basis_gates(self): """Test sdg-gate circuits compiling to backend default basis_gates.""" circuits = ref_1q_clifford.sdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_sdg_gate_nondeterministic_waltz_basis_gates(self): """Test sdg-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_1q_clifford.sdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_sdg_gate_nondeterministic_minimal_basis_gates(self): """Test sdg-gate gate circuits compiling to u3,cx""" circuits = ref_1q_clifford.sdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.sdg_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test cx-gate # --------------------------------------------------------------------- def test_cx_gate_deterministic_default_basis_gates(self): """Test cx-gate circuits compiling to backend default basis_gates.""" circuits = ref_2q_clifford.cx_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.cx_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cx_gate_deterministic_waltz_basis_gates(self): """Test cx-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.cx_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.cx_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cx_gate_deterministic_minimal_basis_gates(self): """Test cx-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.cx_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.cx_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cx_gate_nondeterministic_default_basis_gates(self): """Test cx-gate circuits compiling to backend default basis_gates.""" circuits = ref_2q_clifford.cx_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.cx_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cx_gate_nondeterministic_waltz_basis_gates(self): """Test cx-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.cx_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.cx_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cx_gate_nondeterministic_minimal_basis_gates(self): """Test cx-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.cx_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.cx_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test cz-gate # --------------------------------------------------------------------- def test_cz_gate_deterministic_default_basis_gates(self): """Test cz-gate circuits compiling to backend default basis_gates.""" circuits = ref_2q_clifford.cz_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.cz_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cz_gate_deterministic_waltz_basis_gates(self): """Test cz-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.cz_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.cz_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cz_gate_deterministic_minimal_basis_gates(self): """Test cz-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.cz_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.cz_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cz_gate_nondeterministic_default_basis_gates(self): """Test cz-gate circuits compiling to backend default basis_gates.""" circuits = ref_2q_clifford.cz_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.cz_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cz_gate_nondeterministic_waltz_basis_gates(self): """Test cz-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.cz_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.cz_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cz_gate_nondeterministic_minimal_basis_gates(self): """Test cz-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.cz_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.cz_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test cu1 gate # --------------------------------------------------------------------- def test_cu1_gate_nondeterministic_default_basis_gates(self): """Test cu1-gate gate circuits compiling to default basis""" circuits = ref_non_clifford.cu1_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.cu1_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cu1_gate_nondeterministic_waltz_basis_gates(self): """Test cu1-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.cu1_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.cu1_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cu1_gate_nondeterministic_minimal_basis_gates(self): """"Test cu1-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.cu1_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.cu1_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test cu3 gate # --------------------------------------------------------------------- def test_cu3_gate_deterministic_default_basis_gates(self): """Test cu3-gate gate circuits compiling to default basis""" circuits = ref_non_clifford.cu3_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.cu3_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cu3_gate_deterministic_waltz_basis_gates(self): """Test cu3-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.cu3_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.cu3_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cu3_gate_deterministic_minimal_basis_gates(self): """"Test cu3-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.cu3_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.cu3_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test cswap gate # --------------------------------------------------------------------- def test_cswap_gate_deterministic_default_basis_gates(self): """Test cswap-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.cswap_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.cswap_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary( result, circuits, targets ) # --------------------------------------------------------------------- # Test swap-gate # --------------------------------------------------------------------- def test_swap_gate_deterministic_default_basis_gates(self): """Test swap-gate circuits compiling to backend default basis_gates.""" circuits = ref_2q_clifford.swap_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_swap_gate_deterministic_waltz_basis_gates(self): """Test swap-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.swap_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_swap_gate_deterministic_minimal_basis_gates(self): """Test swap-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.swap_gate_circuits_deterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_swap_gate_nondeterministic_default_basis_gates(self): """Test swap-gate circuits compiling to backend default basis_gates.""" circuits = ref_2q_clifford.swap_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_swap_gate_nondeterministic_waltz_basis_gates(self): """Test swap-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_2q_clifford.swap_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_swap_gate_nondeterministic_minimal_basis_gates(self): """Test swap-gate gate circuits compiling to u3,cx""" circuits = ref_2q_clifford.swap_gate_circuits_nondeterministic( final_measure=False) targets = ref_2q_clifford.swap_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test t-gate # --------------------------------------------------------------------- def test_t_gate_deterministic_default_basis_gates(self): """Test t-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.t_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.t_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_t_gate_deterministic_waltz_basis_gates(self): """Test t-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.t_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.t_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_t_gate_deterministic_minimal_basis_gates(self): """Test t-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.t_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.t_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_t_gate_nondeterministic_default_basis_gates(self): """Test t-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.t_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.t_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_t_gate_nondeterministic_waltz_basis_gates(self): """Test t-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.t_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.t_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_t_gate_nondeterministic_minimal_basis_gates(self): """Test t-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.t_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.t_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test tdg-gate # --------------------------------------------------------------------- def test_tdg_gate_deterministic_default_basis_gates(self): """Test tdg-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.tdg_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.tdg_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_tdg_gate_deterministic_waltz_basis_gates(self): """Test tdg-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.tdg_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.tdg_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_tdg_gate_deterministic_minimal_basis_gates(self): """Test tdg-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.tdg_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.tdg_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_tdg_gate_nondeterministic_default_basis_gates(self): """Test tdg-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.tdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.tdg_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_tdg_gate_nondeterministic_waltz_basis_gates(self): """Test tdg-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.tdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.tdg_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_tdg_gate_nondeterministic_minimal_basis_gates(self): """Test tdg-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.tdg_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.tdg_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test ccx-gate # --------------------------------------------------------------------- def test_ccx_gate_deterministic_default_basis_gates(self): """Test ccx-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.ccx_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_ccx_gate_deterministic_waltz_basis_gates(self): """Test ccx-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.ccx_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_ccx_gate_deterministic_minimal_basis_gates(self): """Test ccx-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.ccx_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_ccx_gate_nondeterministic_default_basis_gates(self): """Test ccx-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.ccx_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_ccx_gate_nondeterministic_waltz_basis_gates(self): """Test ccx-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.ccx_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_ccx_gate_nondeterministic_minimal_basis_gates(self): """Test ccx-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.ccx_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.ccx_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test unitary gate qobj instruction # --------------------------------------------------------------------- def test_unitary_gate(self): """Test simulation with unitary gate circuit instructions.""" circuits = ref_unitary_gate.unitary_gate_circuits_deterministic( final_measure=False) targets = ref_unitary_gate.unitary_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_diagonal_gate(self): """Test simulation with diagonal gate circuit instructions.""" circuits = ref_diagonal_gate.diagonal_gate_circuits_deterministic( final_measure=False) targets = ref_diagonal_gate.diagonal_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cswap_gate_deterministic_minimal_basis_gates(self): """Test cswap-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.cswap_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.cswap_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cswap_gate_deterministic_waltz_basis_gates(self): """Test cswap-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.cswap_gate_circuits_deterministic( final_measure=False) targets = ref_non_clifford.cswap_gate_unitary_deterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cswap_gate_nondeterministic_default_basis_gates(self): """Test cswap-gate circuits compiling to backend default basis_gates.""" circuits = ref_non_clifford.cswap_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.cswap_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cswap_gate_nondeterministic_minimal_basis_gates(self): """Test cswap-gate gate circuits compiling to u3,cx""" circuits = ref_non_clifford.cswap_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.cswap_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) def test_cswap_gate_nondeterministic_waltz_basis_gates(self): """Test cswap-gate gate circuits compiling to u1,u2,u3,cx""" circuits = ref_non_clifford.cswap_gate_circuits_nondeterministic( final_measure=False) targets = ref_non_clifford.cswap_gate_unitary_nondeterministic() job = execute(circuits, self.SIMULATOR, shots=1, basis_gates=['u1', 'u2', 'u3', 'cx'], **self.BACKEND_OPTS) result = job.result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets) # --------------------------------------------------------------------- # Test global phase # --------------------------------------------------------------------- def test_qobj_global_phase(self): """Test qobj global phase.""" circuits = ref_1q_clifford.h_gate_circuits_nondeterministic( final_measure=False) targets = ref_1q_clifford.h_gate_unitary_nondeterministic() qobj = assemble(transpile(circuits, self.SIMULATOR), shots=1, **self.BACKEND_OPTS) # Set global phases for i, _ in enumerate(circuits): global_phase = (-1)**i * (pi / 4) qobj.experiments[i].header.global_phase = global_phase targets[i] = exp(1j * global_phase) * targets[i] result = self.SIMULATOR.run(qobj).result() self.assertSuccess(result) self.compare_unitary(result, circuits, targets, ignore_phase=False)