示例#1
0
def test_cphase_gates():
    for _ in range(REPS):
        theta = random.uniform(-4 * pi, +4 * pi)

        gate11 = qf.control_gate(0, qf.PHASE(theta, 1))
        assert qf.gates_close(gate11, qf.CPHASE(theta, 0, 1))

        gate01 = qf.conditional_gate(0, qf.PHASE(theta, 1), qf.I(1))
        assert qf.gates_close(gate01, qf.CPHASE01(theta))

        gate00 = qf.identity_gate(2)
        gate00 = qf.X(0) @ gate00
        gate00 = qf.X(1) @ gate00
        gate00 = gate11 @ gate00
        gate00 = qf.X(0) @ gate00
        gate00 = qf.X(1) @ gate00
        assert qf.gates_close(gate00, qf.CPHASE00(theta))

        gate10 = qf.identity_gate(2)
        gate10 = qf.X(0) @ gate10
        gate10 = qf.X(1) @ gate10
        gate10 = gate01 @ gate10
        gate10 = qf.X(0) @ gate10
        gate10 = qf.X(1) @ gate10
        assert qf.gates_close(gate10, qf.CPHASE10(theta))
示例#2
0
def test_conditional_gate() -> None:
    controlled_gate = qf.conditional_gate(0, qf.X(1), qf.Y(1))

    state = qf.zero_state(2)
    state = controlled_gate.run(state)
    assert state.tensor[0, 1] == 1.0

    state = qf.X(0).run(state)
    state = controlled_gate.run(state)
    assert 1.0j * state.tensor[1, 0] == 1.0
示例#3
0
def test_conditional_gate():
    controlled_gate = qf.conditional_gate(0, qf.X(1), qf.Y(1))

    state = qf.zero_state(2)
    state = controlled_gate.run(state)
    assert state.vec.asarray()[0, 1] == ALMOST_ONE

    state = qf.X(0).run(state)
    state = controlled_gate.run(state)
    assert 1.0j * state.vec.asarray()[1, 0] == ALMOST_ONE