def test_get_probabilities_returns_correct_result(self): api = MockApiClient() backend = QIBackend(quantum_inspire_api=api) value_a = 0.4892578125 value_b = 0.5097656250 backend._measured_states = { 0: value_a, 11: value_b } # 00000000 and 00001011 expected = {'00': value_a, '11': value_b} backend.main_engine = MagicMock() backend._measured_ids = [0, 1] backend.main_engine.mapper.current_mapping = [0, 1] actual = backend.get_probabilities([MagicMock(id=0), MagicMock(id=1)]) self.assertDictEqual(expected, actual)
password = getpass() else: email, password = QI_EMAIL, QI_PASSWORD return get_basic_authentication(email, password) if __name__ == '__main__': name = 'TestProjectQ' authentication = get_authentication() qi_api = QuantumInspireAPI(QI_URL, authentication, project_name=name) compiler_engines = restrictedgateset.get_engine_list(one_qubit_gates="any", two_qubit_gates=(CNOT,)) compiler_engines.extend([ResourceCounter()]) qi_backend = QIBackend(quantum_inspire_api=qi_api) engine = MainEngine(backend=qi_backend, engine_list=compiler_engines) qubits = engine.allocate_qureg(2) q1 = qubits[0] q2 = qubits[1] H | q1 CNOT | (q1, q2) All(Measure) | qubits engine.flush() print('\nMeasured: {0}'.format([int(q) for q in qubits])) print('Probabilities {0}'.format(qi_backend.get_probabilities(qubits)))