def test_qasm_qdef(): # weaker test condition (str) since we don't have access to the actual class q = Qasm("def Q,0,Q",'qubit q0','Q q0') Qgate = CreateOneQubitGate('Q') assert str(q.get_circuit()) == 'Q(0)' q = Qasm("def CQ,1,Q", 'qubit q0', 'qubit q1', 'CQ q0,q1') Qgate = CreateCGate('Q') assert str(q.get_circuit()) == 'C((1),Q(0))'
def test_qasm_ex1_methodcalls(): q = Qasm() q.qubit('q_0') q.qubit('q_1') q.h('q_0') q.cnot('q_0', 'q_1') assert q.get_circuit() == CNOT(1, 0) * H(1)
def test_qasm_ex1_methodcalls(): q = Qasm() q.qubit("q_0") q.qubit("q_1") q.h("q_0") q.cnot("q_0", "q_1") assert q.get_circuit() == CNOT(1, 0) * H(1)
def test_qasm_1q(): for symbol, gate in [ ("x", X), ("z", Z), ("h", H), ("s", S), ("t", T), ("measure", Mz), ]: q = Qasm("qubit q_0", "%s q_0" % symbol) assert q.get_circuit() == gate(0)
def test_qasm_ex1_methodcalls(): q = Qasm() q.qubit('q_0') q.qubit('q_1') q.h('q_0') q.cnot('q_0', 'q_1') assert q.get_circuit() == CNOT(1,0)*H(1)
def test_qasm_ex2(): q = Qasm( "qubit q_0", "qubit q_1", "qubit q_2", "h q_1", "cnot q_1,q_2", "cnot q_0,q_1", "h q_0", "measure q_1", "measure q_0", "c-x q_1,q_2", "c-z q_0,q_2", ) assert q.get_circuit() == CGate(2, Z(0)) * CGate(1, X(0)) * Mz(2) * Mz(1) * H( 2 ) * CNOT(2, 1) * CNOT(1, 0) * H(1)
def test_qasm_qdef(): # weaker test condition (str) since we don't have access to the actual class q = Qasm("def Q,0,Q", 'qubit q0', 'Q q0') assert str(q.get_circuit()) == 'Q(0)' q = Qasm("def CQ,1,Q", 'qubit q0', 'qubit q1', 'CQ q0,q1') assert str(q.get_circuit()) == 'C((1),Q(0))'
def test_qasm_qdef(): # weaker test condition (str) since we don't have access to the actual class q = Qasm("def Q,0,Q", "qubit q0", "Q q0") assert str(q.get_circuit()) == "Q(0)" q = Qasm("def CQ,1,Q", "qubit q0", "qubit q1", "CQ q0,q1") assert str(q.get_circuit()) == "C((1),Q(0))"
def test_qasm_swap(): q = Qasm('qubit q0', 'qubit q1', 'cnot q0,q1', 'cnot q1,q0', 'cnot q0,q1') assert q.get_circuit() == CNOT(1, 0) * CNOT(0, 1) * CNOT(1, 0)
def test_qasm_swap(): q = Qasm('qubit q0', 'qubit q1', 'cnot q0,q1', 'cnot q1,q0', 'cnot q0,q1') assert q.get_circuit() == CNOT(1,0)*CNOT(0,1)*CNOT(1,0)
def test_qasm_ex1(): q = Qasm('qubit q0', 'qubit q1', 'h q0', 'cnot q0,q1') assert q.get_circuit() == CNOT(1, 0) * H(1)
def display(self): print(self.qasm) Qasm(*self.qasm).plot()
def test_qasm_3q(): q = Qasm("qubit q0", "qubit q1", "qubit q2", "toffoli q2,q1,q0") assert q.get_circuit() == CGateS((0, 1), X(2))
def test_qasm_2q(): for symbol, gate in [("cnot", CNOT), ("swap", SWAP), ("cphase", CPHASE)]: q = Qasm("qubit q_0", "qubit q_1", "%s q_0,q_1" % symbol) assert q.get_circuit() == gate(1, 0)
def test_qasm_ex2(): q = Qasm('qubit q_0', 'qubit q_1', 'qubit q_2', 'h q_1', 'cnot q_1,q_2', 'cnot q_0,q_1', 'h q_0', 'measure q_1', 'measure q_0', 'c-x q_1,q_2', 'c-z q_0,q_2') assert q.get_circuit() == CGate(2,Z(0))*CGate(1,X(0))*Mz(2)*Mz(1)*H(2)*CNOT(2,1)*CNOT(1,0)*H(1)
def test_qasm_1q(): for symbol, gate in [('x', X), ('z', Z), ('h', H), ('s', S), ('t', T), ('measure', Mz)]: q = Qasm('qubit q_0', '%s q_0' % symbol) assert q.get_circuit() == gate(0)
def test_qasm_2q(): for symbol, gate in [('cnot', CNOT), ('swap', SWAP), ('cphase', CPHASE)]: q = Qasm('qubit q_0', 'qubit q_1', '%s q_0,q_1' % symbol) assert q.get_circuit() == gate(1, 0)
def test_qasm_ex2(): q = Qasm('qubit q_0', 'qubit q_1', 'qubit q_2', 'h q_1', 'cnot q_1,q_2', 'cnot q_0,q_1', 'h q_0', 'measure q_1', 'measure q_0', 'c-x q_1,q_2', 'c-z q_0,q_2') assert q.get_circuit() == CGate(2, Z(0)) * CGate( 1, X(0)) * Mz(2) * Mz(1) * H(2) * CNOT(2, 1) * CNOT(1, 0) * H(1)
def test_qasm_ex1(): q = Qasm("qubit q0", "qubit q1", "h q0", "cnot q0,q1") assert q.get_circuit() == CNOT(1, 0) * H(1)
def test_qasm_2q(): for symbol, gate in [('cnot', CNOT), ('swap', SWAP), ('cphase', CPHASE)]: q = Qasm('qubit q_0', 'qubit q_1', '%s q_0,q_1' % symbol) assert q.get_circuit() == gate(1,0)
def test_qasm_3q(): q = Qasm('qubit q0', 'qubit q1', 'qubit q2', 'toffoli q2,q1,q0') assert q.get_circuit() == CGateS((0,1),X(2))
def test_qasm_1q(): for symbol, gate in [('x', X), ('z', Z), ('h', H), ('s', S), ('t', T), ('measure', Mz)]: q = Qasm('qubit q_0', '%s q_0' % symbol) assert q.get_circuit() == gate(0)
def test_qasm_swap(): q = Qasm("qubit q0", "qubit q1", "cnot q0,q1", "cnot q1,q0", "cnot q0,q1") assert q.get_circuit() == CNOT(1, 0) * CNOT(0, 1) * CNOT(1, 0)
def test_qasm_3q(): q = Qasm('qubit q0', 'qubit q1', 'qubit q2', 'toffoli q2,q1,q0') assert q.get_circuit() == CGateS((0, 1), X(2))
def test_qasm_ex1(): q = Qasm('qubit q0', 'qubit q1', 'h q0', 'cnot q0,q1') assert q.get_circuit() == CNOT(1,0)*H(1)