def test_for_non_fsp_measurements_at_begin_and_end(self): with patch.object(QuantumInspireBackend, "_submit_experiment", return_value=Mock()) as result_experiment: api = Mock() project = {'id': 42} api.create_project.return_value = project api.execute_qasm_async.return_value = 42 api.get_backend_type_by_name.return_value = { 'max_number_of_shots': 4096 } simulator = QuantumInspireBackend(api, Mock()) qc = QuantumCircuit(2, 2) qc.measure(0, 0) qc.cx(0, 1) qc.x(0) qc.measure(1, 1) simulator.run(qc, 25) experiment = self._circuit_to_experiment(qc) result_experiment.assert_called_once_with(experiment, 25, project=project, full_state_projection=False)
def test_for_non_fsp_hardware_backend(self): with patch.object(QuantumInspireBackend, "_submit_experiment", return_value=Mock()) as result_experiment: api = Mock() project = {'id': 42} api.create_project.return_value = project api.execute_qasm_async.return_value = 42 api.get_backend_type_by_name.return_value = { 'max_number_of_shots': 4096 } config = QuantumInspireBackend.DEFAULT_CONFIGURATION config.backend_name = 'qi_hardware' config.simulator = False simulator = QuantumInspireBackend(api, config) qc = QuantumCircuit(2, 2) qc.cx(0, 1) qc.x(0) simulator.run(qc, 25) experiment = self._circuit_to_experiment(qc) result_experiment.assert_called_once_with(experiment, 25, project=project, full_state_projection=False)
def test_for_fsp_no_measurements(self): with patch.object(QuantumInspireBackend, "_submit_experiment", return_value=Mock()) as result_experiment: api = Mock() project = {'id': 42} api.create_project.return_value = project api.get_jobs_from_project.return_value = [] api.execute_qasm_async.return_value = 42 simulator = QuantumInspireBackend(api, Mock()) instructions = [{ 'name': 'cx', 'qubits': [0, 1] }, { 'name': 'x', 'qubits': [0] }] experiment = self._basic_experiment_dictionary experiment['instructions'] = instructions qjob_dict = self._basic_qobj_dictionary qjob_dict['experiments'][0] = experiment qobj = QasmQobj.from_dict(qjob_dict) experiment = qobj.experiments[0] simulator.run(qobj) result_experiment.assert_called_once_with(experiment, 25, project=project, full_state_projection=True)
def test_valid_non_fsp_measurement_qubit_to_classical(self): api = Mock() api.create_project.return_value = {'id': 42} api.get_asset_from_job.return_value = {'project_id': '42'} quantum_inspire_job = Mock() quantum_inspire_job.get_project_identifier.return_value = 42 api.execute_qasm_async.return_value = quantum_inspire_job api.get_backend_type_by_name.return_value = { 'max_number_of_shots': 4096 } simulator = QuantumInspireBackend(api, Mock()) q = QuantumRegister(3, "q") c1 = ClassicalRegister(1, "c1") c2 = ClassicalRegister(1, "c2") qc = QuantumCircuit(q, c1, c2, name="test") qc.h(0) qc.h(2) qc.measure(1, 0) qc.measure(0, 1) qc.h(1).c_if(c2, 1) qc.measure(0, 1) qc.measure(1, 0) job = simulator.run(qc) self.assertEqual('42', job.job_id())
def test_run_returns_correct_result_for_my_project_number(self): default_project_number = 42 my_project_number = 43 api = Mock() api.create_project.return_value = {'id': default_project_number} quantum_inspire_job = Mock() quantum_inspire_job.get_project_identifier.return_value = my_project_number api.execute_qasm_async.return_value = quantum_inspire_job api.get_backend_type_by_name.return_value = { 'max_number_of_shots': 4096 } simulator = QuantumInspireBackend(api, Mock()) q = QuantumRegister(3, "q") c1 = ClassicalRegister(2, "c1") c2 = ClassicalRegister(1, "c2") qc = QuantumCircuit(q, c1, c2, name="test") qc.h(q[0]) qc.h(q[2]) qc.measure(q[1], c1[0]) qc.measure(q[0], c1[1]) qc.h(q[1]).c_if(c1, 2) qc.measure(q[0], c1[1]) qc.measure(q[1], c1[0]) job = simulator.run(qc) api.delete_project.assert_called_with(default_project_number) self.assertEqual(my_project_number, int(job.job_id()))
def test_run_returns_correct_result(self): api = Mock() api.create_project.return_value = {'id': 42} api.get_jobs_from_project.return_value = [] api.execute_qasm_async.return_value = 42 api.get_backend_type_by_name.return_value = {'max_number_of_shots': 4096} simulator = QuantumInspireBackend(api, Mock()) instructions = [{'name': 'cx', 'qubits': [0, 1], 'memory': [0, 1]}, {'name': 'measure', 'qubits': [0], 'memory': [1]}] qobj_dict = self._basic_qobj_dictionary qobj_dict['experiments'][0]['instructions'] = instructions qobj = QasmQobj.from_dict(qobj_dict) job = simulator.run(qobj) self.assertEqual('42', job.job_id())
def test_run_a_circuit_returns_correct_result(self): api = Mock() type(api).__name__ = 'QuantumInspireAPI' api.create_project.return_value = {'id': 42} api.get_asset_from_job.return_value = {'project_id': '42'} api.execute_qasm_async.return_value = QuantumInspireJob(api, 42) api.get_backend_type_by_name.return_value = { 'max_number_of_shots': 4096 } simulator = QuantumInspireBackend(api, Mock()) qc = QuantumCircuit(2, 2) qc.cx(0, 1) qc.measure(0, 1) job = simulator.run(qc, shots=1024) self.assertEqual('42', job.job_id())
def test_valid_non_fsp_measurement_qubit_to_classical(self): api = Mock() api.create_project.return_value = {'id': 42} api.get_jobs_from_project.return_value = [] api.execute_qasm_async.return_value = 42 simulator = QuantumInspireBackend(api, Mock()) instructions = [{ 'name': 'h', 'qubits': [0] }, { 'name': 'h', 'qubits': [2] }, { 'memory': [0], 'name': 'measure', 'qubits': [1] }, { 'memory': [1], 'name': 'measure', 'qubits': [0] }, { 'mask': '0x2', 'name': 'bfunc', 'register': 7, 'relation': '==', 'val': '0x2' }, { 'conditional': 7, 'name': 'h', 'qubits': [1] }, { 'memory': [1], 'name': 'measure', 'qubits': [0] }, { 'memory': [0], 'name': 'measure', 'qubits': [1] }] qobj_dict = self._basic_qobj_dictionary qobj_dict['experiments'][0]['instructions'] = instructions qobj = QasmQobj.from_dict(qobj_dict) job = simulator.run(qobj) self.assertEqual('42', job.job_id())