示例#1
0
def test_teleportation():
    circuit = Circuit()
    circuit.add(Qubits(3))
    circuit.add(CNOT(1, 2))
    circuit.add(CNOT(0, 1))
    circuit.add(Hadamard(0))
    circuit.add(Measure([0, 1]))

    result = circuit.run(1024).result

    # All 16 states should be relatively equal probability
    if result["11"] == 1024:
        circuit.add(PauliX(2))
        circuit.add(PauliZ(2))
    elif result["10"] == 1024:
        circuit.add(PauliZ(2))
    elif result["01"] == 1024:
        circuit.add(PauliX(2))
    circuit.add(Measure([2]))

    result2 = circuit.run(1024).result

    # TODO: Fix this test.

    assert result2
示例#2
0
def test_dblpx_integration():
    circuit = Circuit()
    circuit.add(Qubits(2))
    circuit.add(PauliX(0))
    circuit.add(PauliX(1))
    circuit.add(Measure(0, 1))
    job = circuit.run(1024)
    result = job.result
    assert result["11"] == 1024
    assert result["00"] == 0
    assert result["10"] == 0
    assert result["01"] == 0
示例#3
0
def test_dblpx_integration():
    circuit = Circuit()
    circuit.add(Qubits(2))
    circuit.add(PauliX(0))
    circuit.add(PauliX(1))

    sess = QSession(backend=QuantumSimulator())
    result = sess.run(circuit, num_shots=1024)

    assert result['11'] == 1024
    assert result['00'] == 0
    assert result['10'] == 0
    assert result['01'] == 0
示例#4
0
def test_paulix_init():
    from shor.gates import PauliX, X
    gate1 = X()
    gate2 = PauliX()
    assert gate1.__class__ == gate2.__class__
    # Try with parameter
    X(0)
示例#5
0
def test_paulix_matrix():
    from shor.gates import PauliX, X
    gates = [PauliX(), X()]

    for g in gates:
        assert is_square(g.to_matrix())
        assert is_unitary(g.to_matrix())
        assert np.array_equal(g.to_matrix(), np.array([[0, 1], [1, 0]]))
示例#6
0
def test_ccnot_integration():
    circuit = Circuit()
    circuit.add(Qubits(3))
    circuit.add(PauliX(0))
    circuit.add(PauliX(1))
    circuit.add(CCNOT(0, 1, 2))
    circuit.add(Measure([0, 1, 2]))
    job = circuit.run(1024)
    result = job.result

    assert result["000"] == 0
    assert result["001"] == 0
    assert result["010"] == 0
    assert result["100"] == 0
    assert result["110"] == 0
    assert result["101"] == 0
    assert result["011"] == 0
    assert result["111"] == 1024
示例#7
0
def test_ccnot_integration():
    circuit = Circuit()
    circuit.add(Qubits(3))
    circuit.add(PauliX(0))
    circuit.add(PauliX(1))
    circuit.add(CCNOT(0, 1, 2))
    circuit.add(Measure(0, 1, 2))

    sess = QSession(backend=QuantumSimulator())
    result = sess.run(circuit, num_shots=1024)

    assert result['000'] == 0
    assert result['001'] == 0
    assert result['010'] == 0
    assert result['100'] == 0
    assert result['110'] == 0
    assert result['101'] == 0
    assert result['011'] == 0
    assert result['111'] == 1024
示例#8
0
def test_u1_integration():
    circuit = Circuit()
    circuit.add(Qubits(1))
    circuit.add(PauliX(0))
    circuit.add(U1(0))
    circuit.add(Measure([0]))
    job = circuit.run(1024)
    result = job.result
    assert result["0"] == 0
    assert result["1"] == 1024
示例#9
0
def test_paulix_integration():
    circuit = Circuit()
    circuit.add(Qubits(1))
    circuit.add(PauliX(0))  # Can also use H()
    circuit.add(Measure([0]))
    job = circuit.run(1024)
    result = job.result
    # Accounting for random noise, results won't be exact
    assert result["0"] == 0
    assert result["1"] == 1024
示例#10
0
def test_sdg_integration():
    circuit = Circuit()
    circuit.add(Qubits(1))
    circuit.add(PauliX(0))
    circuit.add(Sdg(0))  # Can also use H()
    circuit.add(Measure([0]))
    job = circuit.run(1024)
    result = job.result
    assert result["1"] == 1024
    assert result["0"] == 0
示例#11
0
def test_u1_integration():
    circuit = Circuit()
    circuit.add(Qubits(1))
    circuit.add(PauliX(0))
    circuit.add(U1(0))
    circuit.add(Measure())

    sess = QSession(backend=QuantumSimulator())
    result = sess.run(circuit, num_shots=1024)

    assert result['0'] == 0
    assert result['1'] == 1024
示例#12
0
def test_paulix_integration():
    circuit = Circuit()
    circuit.add(Qubits(1))
    circuit.add(PauliX(0))  # Can also use H()
    circuit.add(Measure())

    sess = QSession(backend=QuantumSimulator())
    result = sess.run(circuit, num_shots=1024)

    # Accounting for random noise, results won't be exact
    assert result['0'] == 0
    assert result['1'] == 1024
示例#13
0
def test_cz2_int():
    circuit_1 = Circuit()
    circuit_1.add(Qubits(2))
    circuit_1.add(PauliX(0))
    circuit_1.add(Cz(0, 1))
    circuit_1.add(Measure(0, 1))

    result_1 = circuit_1.run(1024).result

    assert result_1["00"] == 0
    assert result_1["11"] == 0
    assert result_1["01"] == 1024
    assert result_1["10"] == 0
示例#14
0
def test_swap_integration():  #
    circuit = Circuit()
    circuit.add(Qubits(2))
    circuit.add(PauliX(0))
    circuit.add(SWAP(0, 1))
    circuit.add(Measure(0, 1))

    sess = QSession(backend=QuantumSimulator())
    result = sess.run(circuit, num_shots=1024)

    assert result['11'] == 0
    assert result['00'] == 0
    assert result['10'] == 0
    assert result['01'] == 1024
示例#15
0
def test_multi_gate_int():
    circuit_1 = Circuit()
    circuit_1.add(Qubits(2))
    circuit_1.add(PauliX(0))
    circuit_1.add(CNOT(0, 1))
    circuit_1.add(CH(0, 1))
    circuit_1.add(Measure(0, 1))

    result_1 = circuit_1.run(1024).result

    assert result_1["00"] == 0
    assert result_1["11"] > 450
    assert result_1["01"] > 450
    assert result_1["10"] == 0