def test_logic(self): circ = make_simple_logic() task = Task(circ, get_pylinalg_qpu()) for res in task.states(): self.assertEqual(int(res.intermediate_measurements[0].cbits[0]), 1) self.assertEqual(int(res.intermediate_measurements[1].cbits[0]), 0)
def test_analyze_mode(self): circuit = generate_bell_state() task = Task(circuit, get_qpu_server()) for state in task.states(): self.assertAlmostEqual(state.probability, 0.5)
def test_cc(self): circ = make_c_control_circuit() task = Task(circ, get_pylinalg_qpu()) for res in task.states(): self.assertEqual(res.intermediate_measurements[0].cbits[0], 1) self.assertEqual(res.intermediate_measurements[1].cbits[0], 1)
def test_bit_ordering(self): circ = generate_bit_ordering() for n_shots in [0, 10]: # for expected_res, qbits in [(2, [0, 1, 2, 3]), (1, [0, 1, 2])]: for expected_res, qbits in [(2, [0, 1, 2, 3]), (1, [0, 1, 2]), (2, [2, 3]), (1, [3, 2])]: ref_task = Task(circ, get_qpu_server()) if n_shots == 0: for res in ref_task.states(qbits=qbits): self.assertEqual(res.state.int, expected_res) else: for res in ref_task.execute(nb_samples=n_shots, qbits=qbits): self.assertEqual(res.state.int, expected_res)
def test_break(self): circ = generate_break() task = Task(circ, get_qpu_server()) exp = exception_types.QPUException(exception_types.ErrorType.BREAK) exp = exception_types.QPUException(exception_types.ErrorType.BREAK) raised = False try: res = task.execute() except exception_types.QPUException as Exp: self.assertEqual(Exp.code, 10) self.assertEqual(Exp.modulename, "qat.pylinalg") raised = True self.assertTrue(raised)
def test_reset(self): """test that reset gate works FIXME in 'analyze' mode, not testing intermediate_measurements FIXME not testing if resetting several qbits """ # program with final state: qbit 0 : 0 with 100% prob, # but intermediate measure can be 0 or 1 with 50% prob prog = Program() reg = prog.qalloc(1) prog.apply(H, reg) prog.reset(reg) circ = prog.to_circ() ref_task = Task(circ, get_pylinalg_qpu()) for res in ref_task.execute(nb_samples=5): self.assertEqual(res.state.int, 0) self.assertAlmostEqual( res.intermediate_measurements[0].probability, 0.5, delta=1e-10)
def test_default_mode(self): circuit = generate_bell_state() task = Task(circuit, get_qpu_server()) result = task.execute() self.assertTrue(result.state.int == result.state.int)
def test_formula_and_cctrl(self): circ = generate_boolean() task = Task(circ, get_qpu_server()) res = task.execute() self.assertEqual(res.state.int, 7)