Example #1
0
def test_take_multi_qubit_bitstring():
    qubits = [qu.create_qubit() for _ in range(3)]
    qubits[0], qubits[1] = gates.controlled_xgate(gates.xgate(qubits[0]),
                                                  qubits[1])
    qubits[1], qubits[2] = gates.controlled_xgate(qubits[1], qubits[2])
    contracted = qu.contract_network(qubits)
    out = qu.take_bitstring(contracted)
    assert out == "111"
Example #2
0
def test_3_qubit_connections():
    # |0> -X-.---
    #        |
    # |0> ---*-.-
    #          |
    # |0> -----*-
    qubits = [qu.create_qubit() for _ in range(3)]
    qubits[0], qubits[1] = gates.controlled_xgate(gates.xgate(qubits[0]),
                                                  qubits[1])
    qubits[1], qubits[2] = gates.controlled_xgate(qubits[1], qubits[2])
    reference = [[[0 + 0j, 0 + 0j], [0 + 0j, 0 + 0j]],
                 [[0 + 0j, 0 + 0j], [0 + 0j, 1 + 0j]]]
    out = qu.contract_network(qubits).get_tensor()
    np.testing.assert_allclose(out, reference)
Example #3
0
def test_take_single_qubit_bitstring():
    qubits = [gates.xgate(qu.create_qubit())]
    contracted = qu.contract_network(qubits)
    out = qu.take_bitstring(contracted)
    assert out == '1'
Example #4
0
def test_bitstring_rejects_uncontracted():
    qubits = [gates.xgate(qu.create_qubit())]
    with pytest.raises(ValueError):
        out = qu.take_bitstring(qubits[0].node1)
Example #5
0
def test_eval_probability_rejects_uncontracted():
  q_0 = qu.create_qubit()
  gate = gates.xgate(q_0)
  with pytest.raises(ValueError):
    state = qu.eval_probability(q_0)