Exemple #1
0
 def __store_function_assert_equal(self,
                                   identity,
                                   gate,
                                   qasm,
                                   function_mock,
                                   count=0,
                                   verbose=0):
     api = MockApiClient()
     function_mock.return_value = count
     backend = QIBackend(quantum_inspire_api=api, verbose=verbose)
     command_alloc0 = MagicMock(gate=Allocate,
                                qubits=[[MagicMock(id=identity - 1)]])
     command_alloc1 = MagicMock(gate=Allocate,
                                qubits=[[MagicMock(id=identity)]])
     command_alloc2 = MagicMock(gate=Allocate,
                                qubits=[[MagicMock(id=identity + 1)]])
     command = MagicMock(gate=gate,
                         qubits=[[MagicMock(id=identity)],
                                 [MagicMock(id=identity + 1)]],
                         control_qubits=[
                             MagicMock(id=identity - 1),
                             MagicMock(id=identity)
                         ])
     command_list = [
         command_alloc0, command_alloc1, command_alloc2, command
     ]
     backend.receive(command_list)
     self.assertEqual(backend.qasm, qasm)
Exemple #2
0
 def test_maximum_qubit(self):
     command_alloc0 = MagicMock(gate=Allocate,
                                qubits=[[MagicMock(id=0)],
                                        [MagicMock(id=1)]])
     command_alloc1 = MagicMock(gate=Allocate,
                                qubits=[[MagicMock(id=1)],
                                        [MagicMock(id=1)]])
     command_alloc2 = MagicMock(gate=Allocate,
                                qubits=[[MagicMock(id=2)],
                                        [MagicMock(id=1)]])
     command_dealloc0 = MagicMock(gate=Deallocate,
                                  qubits=[[MagicMock(id=0)],
                                          [MagicMock(id=1)]])
     command_dealloc1 = MagicMock(gate=Deallocate,
                                  qubits=[[MagicMock(id=1)],
                                          [MagicMock(id=1)]])
     command_dealloc2 = MagicMock(gate=Deallocate,
                                  qubits=[[MagicMock(id=2)],
                                          [MagicMock(id=1)]])
     command_list = [
         command_alloc1, command_alloc2, command_dealloc1, command_alloc0,
         command_dealloc0, command_dealloc2
     ]
     api = MockApiClient()
     backend = QIBackend(quantum_inspire_api=api)
     backend.main_engine = MagicMock()
     backend.receive(command_list)
     self.assertEqual(backend._number_of_qubits, 3)
     self.assertEqual(len(backend._allocated_qubits), 0)
Exemple #3
0
 def test_receive(self, function_mock):
     function_mock.return_value = 1
     command = MagicMock(gate=NOT,
                         qubits=[[MagicMock(id=0)], [MagicMock(id=1)]])
     command_list = [command, MagicMock(gate=FlushGate())]
     api = MockApiClient()
     backend = QIBackend(quantum_inspire_api=api)
     backend.main_engine = MagicMock()
     with patch('sys.stdout', new_callable=io.StringIO):
         backend.receive(command_list)
     self.assertEqual(backend.qasm, "")
     self.assertTrue(backend._clear)
Exemple #4
0
 def test_flush_with_no_measurements_but_nfsp(self, function_mock):
     function_mock.return_value = 1
     command_alloc0 = MagicMock(gate=Allocate, qubits=[[MagicMock(id=0)]])
     command_alloc1 = MagicMock(gate=Allocate, qubits=[[MagicMock(id=1)]])
     command_alloc2 = MagicMock(gate=Allocate, qubits=[[MagicMock(id=1)]])
     command_dealloc1 = MagicMock(gate=Deallocate, qubits=[[MagicMock(id=1)]])
     command = MagicMock(gate=NOT, qubits=[[MagicMock(id=0)]], control_qubits=[MagicMock(id=1)])
     command_list = [command_alloc0, command_alloc1, command_dealloc1, command_alloc2, command,
                     MagicMock(gate=FlushGate())]
     api = MockApiClient()
     backend = QIBackend(quantum_inspire_api=api, verbose=1)
     backend.main_engine = MagicMock()
     with patch('sys.stdout', new_callable=io.StringIO):
         backend.receive(command_list)
     self.assertEqual(backend.qasm, "")