Exemplo n.º 1
0
def test_quil_two_qubit_gate_output():
    (
        q0,
        q1,
    ) = _make_qubits(2)
    gate = QuilTwoQubitGate(np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
    output = cirq.QuilOutput(
        (gate.on(q0, q1),),
        (
            q0,
            q1,
        ),
    )
    assert (
        str(output)
        == """# Created using Cirq.

DEFGATE USERGATE1:
    1.0+0.0i, 0.0+0.0i, 0.0+0.0i, 0.0+0.0i
    0.0+0.0i, 1.0+0.0i, 0.0+0.0i, 0.0+0.0i
    0.0+0.0i, 0.0+0.0i, 1.0+0.0i, 0.0+0.0i
    0.0+0.0i, 0.0+0.0i, 0.0+0.0i, 1.0+0.0i
USERGATE1 0 1
"""
    )
Exemplo n.º 2
0
def test_quil_two_qubit_gate_eq():
    gate = QuilTwoQubitGate(np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
    gate2 = QuilTwoQubitGate(np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
    assert cirq.approx_eq(gate, gate2, atol=1e-8)
    gate3 = QuilTwoQubitGate(np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
    gate4 = QuilTwoQubitGate(np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 1]]))
    assert not cirq.approx_eq(gate4, gate3, atol=1e-8)
Exemplo n.º 3
0
def test_quil_two_qubit_gate_output():
    q0, q1, = _make_qubits(2)
    gate = QuilTwoQubitGate(
        np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
    output = cirq.QuilOutput((gate.on(q0, q1),), (
        q0,
        q1,
    ))
    assert str(output) == """# Created using Cirq.
Exemplo n.º 4
0
def test_quil_two_qubit_gate_eq():
    with cirq.testing.assert_deprecated(deadline='v1.0', count=4):
        gate = QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
        gate2 = QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
        assert cirq.approx_eq(gate, gate2, atol=1e-8)
        gate3 = QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
        gate4 = QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 1]]))
        assert not cirq.approx_eq(gate4, gate3, atol=1e-8)
Exemplo n.º 5
0
def test_quil_two_qubit_gate_output():
    (q0, q1) = _make_qubits(2)
    with cirq.testing.assert_deprecated(deadline='v1.0', count=7):
        gate = QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
        output = cirq.QuilOutput((gate.on(q0, q1), ), (q0, q1))
        assert (str(output) == """# Created using Cirq.

DEFGATE USERGATE1:
    1.0+0.0i, 0.0+0.0i, 0.0+0.0i, 0.0+0.0i
    0.0+0.0i, 1.0+0.0i, 0.0+0.0i, 0.0+0.0i
    0.0+0.0i, 0.0+0.0i, 1.0+0.0i, 0.0+0.0i
    0.0+0.0i, 0.0+0.0i, 0.0+0.0i, 1.0+0.0i
USERGATE1 0 1
""")
Exemplo n.º 6
0
def test_quil_two_qubit_gate_repr():
    gate = QuilTwoQubitGate(
        np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
    assert repr(gate) == ("""cirq.circuits.quil_output.QuilTwoQubitGate(matrix=
[[1 0 0 0]
 [0 1 0 0]
 [0 0 1 0]
 [0 0 0 1]]
)""")
Exemplo n.º 7
0
def test_quil_two_qubit_gate_repr():
    with cirq.testing.assert_deprecated(deadline='v1.0', count=1):
        gate = QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]))
        assert repr(gate) == (
            """cirq.circuits.quil_output.QuilTwoQubitGate(matrix=
[[1 0 0 0]
 [0 1 0 0]
 [0 0 1 0]
 [0 0 0 1]]
)""")
Exemplo n.º 8
0
def test_parseable_defgate_output():
    pyquil = pytest.importorskip("pyquil")
    q0, q1 = _make_qubits(2)
    operations = [
        QuilOneQubitGate(np.array([[1, 0], [0, 1]])).on(q0),
        QuilTwoQubitGate(
            np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                      [0, 0, 0, 1]])).on(q0, q1)
    ]
    output = cirq.QuilOutput(operations, (q0, q1))
    # Just checks that we can create a pyQuil Program without crashing.
    pyquil.Program(str(output))