Beispiel #1
0
 def test_hardware_backend2(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(QiskitBackendError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         email = '*****@*****.**'
         secret = 'secret'
         quantum_inpire_provider.set_basic_authentication(email, secret)
         authentication = BasicAuthentication(email, secret)
         api.assert_called_with(QI_URL, authentication, None)
         quantum_inpire_provider._api.get_backend_types.return_value = [
             self.hardware_backend_type2
         ]
         backend = quantum_inpire_provider.get_backend(name='qi_hardware')
         self.assertEqual('qi_hardware', backend.name())
         self.assertEqual(backend.configuration().coupling_map,
                          [[0, 1], [1, 0]])
         self.assertFalse(backend.configuration().simulator)
         self.assertEqual(2, backend.configuration().n_qubits)
         self.assertTrue(backend.configuration().memory)
         self.assertEqual(4096, backend.configuration().max_shots)
         self.assertEqual(1, backend.configuration().max_experiments)
         self.assertFalse(backend.configuration().conditional)
         self.assertEqual(backend.configuration().basis_gates, [
             'rx', 'ry', 'rz', 'x', 'y', 'z', 'h', 'id', 't', 'tdg', 's',
             'sdg', 'cz', 'cx', 'swap', 'ccx', 'u1', 'u2', 'u3'
         ])
 def test_hardware_backend(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(ApiError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         email = '*****@*****.**'
         secret = 'secret'
         quantum_inpire_provider.set_basic_authentication(email, secret)
         authentication = BasicAuthentication(email, secret)
         api.assert_called_with(QI_URL, authentication)
         quantum_inpire_provider._api.get_backend_types.return_value = [
             self.hardware_backend_type
         ]
         backend = quantum_inpire_provider.get_backend(name='qi_hardware')
         self.assertEqual('qi_hardware', backend.name())
         self.assertEqual(backend.configuration().coupling_map, [(0, 2),
                                                                 (1, 2),
                                                                 (2, 0),
                                                                 (2, 1),
                                                                 (2, 3),
                                                                 (2, 4),
                                                                 (3, 2),
                                                                 (4, 2)])
         self.assertFalse(backend.configuration().simulator)
         self.assertEqual(5, backend.configuration().n_qubits)
         self.assertTrue(backend.configuration().memory)
         self.assertEqual(2048, backend.configuration().max_shots)
         self.assertEqual(1, backend.configuration().max_experiments)
         self.assertFalse(backend.configuration().conditional)
         self.assertEqual(backend.configuration().basis_gates,
                          ['rx', 'rz', 'x', 's', 'z', 'h', 'tdg', 'cz'])
Beispiel #3
0
 def test_set_token_authentication(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(QiskitBackendError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         token = 'This_is_a_nice_looking_token'
         quantum_inpire_provider.set_token_authentication(token)
         api.assert_called_once()
Beispiel #4
0
 def test_set_authentication(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(QiskitBackendError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         token = 'This_is_a_nice_looking_token'
         authentication = TokenAuthentication(token, scheme="token")
         quantum_inpire_provider.set_authentication(authentication)
         api.assert_called_with(QI_URL, authentication, None)
         authentication = BasicAuthentication('email', 'password')
         quantum_inpire_provider.set_authentication(authentication)
         api.assert_called_with(QI_URL, authentication, None)
Beispiel #5
0
 def test_set_basic_authentication_with_url(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         api.get_backend_types.return_value = [self.simulator_backend_type]
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(QiskitBackendError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         email = '*****@*****.**'
         secret = 'secret'
         url = 'https/some-api.api'
         quantum_inpire_provider.set_basic_authentication(
             email, secret, url)
         authentication = BasicAuthentication(email, secret)
         api.assert_called_with(url, authentication, None)
Beispiel #6
0
 def test_set_basic_authentication(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(QiskitBackendError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         email = '*****@*****.**'
         secret = 'secret'
         quantum_inpire_provider.set_basic_authentication(email, secret)
         authentication = BasicAuthentication(email, secret)
         api.assert_called_with(QI_URL, authentication, None)
         quantum_inpire_provider._api.get_backend_types.return_value = [
             self.simulator_backend_type
         ]
         backend = quantum_inpire_provider.get_backend(name='qi_simulator')
         self.assertEqual('qi_simulator', backend.name())
Beispiel #7
0
 def test_backends(self):
     with mock.patch(
             'quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI'
     ) as api:
         quantum_inpire_provider = QuantumInspireProvider()
         with self.assertRaises(ApiError):
             quantum_inpire_provider.backends(name='quantum-inspire')
         email = '*****@*****.**'
         secret = 'secret'
         quantum_inpire_provider.set_basic_authentication(email, secret)
         authentication = BasicAuthentication(email, secret)
         api.assert_called_with(QI_URL, authentication)
         quantum_inpire_provider._api.get_backend_types.return_value = [{
             'name':
             'qi_simulator',
             'is_allowed':
             True
         }]
         backend = quantum_inpire_provider.get_backend(name='qi_simulator')
         self.assertEqual('qi_simulator', backend.name())
         with self.assertRaises(QiskitBackendNotFoundError) as error:
             quantum_inpire_provider.get_backend(name='not-quantum-inspire')
         self.assertEqual(('No backend matches the criteria', ),
                          error.exception.args)