Esempio n. 1
0
def test_to_clifford_tableau_util_function():

    tableau = cirq.ops.clifford_gate._to_clifford_tableau(
        x_to=cirq.PauliTransform(to=cirq.X, flip=False),
        z_to=cirq.PauliTransform(to=cirq.Z, flip=False),
    )
    assert tableau == cirq.CliffordTableau(num_qubits=1, initial_state=0)

    tableau = cirq.ops.clifford_gate._to_clifford_tableau(
        x_to=cirq.PauliTransform(to=cirq.X, flip=False),
        z_to=cirq.PauliTransform(to=cirq.Z, flip=True),
    )
    assert tableau == cirq.CliffordTableau(num_qubits=1, initial_state=1)

    tableau = cirq.ops.clifford_gate._to_clifford_tableau(
        rotation_map={
            cirq.X: cirq.PauliTransform(to=cirq.X, flip=False),
            cirq.Z: cirq.PauliTransform(to=cirq.Z, flip=False),
        }
    )
    assert tableau == cirq.CliffordTableau(num_qubits=1, initial_state=0)

    tableau = cirq.ops.clifford_gate._to_clifford_tableau(
        rotation_map={
            cirq.X: cirq.PauliTransform(to=cirq.X, flip=False),
            cirq.Z: cirq.PauliTransform(to=cirq.Z, flip=True),
        }
    )
    assert tableau == cirq.CliffordTableau(num_qubits=1, initial_state=1)

    with pytest.raises(ValueError):
        cirq.ops.clifford_gate._to_clifford_tableau()
Esempio n. 2
0
def test_init_90rot_from_single(trans, frm):
    gate = cirq.SingleQubitCliffordGate.from_single_map({frm: trans})
    assert gate.transform(frm) == trans
    _assert_not_mirror(gate)
    _assert_no_collision(gate)
    # Check that it decomposes to one gate
    assert len(gate.decompose_rotation()) == 1
    # Check that this is a 90 degree rotation gate
    assert (gate.merged_with(gate).merged_with(gate).merged_with(gate) ==
            cirq.SingleQubitCliffordGate.I)
    # Check that flipping the transform produces the inverse rotation
    trans_rev = cirq.PauliTransform(trans.to, not trans.flip)
    gate_rev = cirq.SingleQubitCliffordGate.from_single_map({frm: trans_rev})
    assert gate**-1 == gate_rev
Esempio n. 3
0
def _all_rotation_pairs():
    for px, flip_x, pz, flip_z in itertools.product(cirq.Pauli.XYZ, _bools,
                                                    cirq.Pauli.XYZ, _bools):
        if px == pz:
            continue
        yield cirq.PauliTransform(px, flip_x), cirq.PauliTransform(pz, flip_z)
Esempio n. 4
0
def _all_rotations():
    for pauli, flip, in itertools.product(cirq.Pauli.XYZ, _bools):
        yield cirq.PauliTransform(pauli, flip)
Esempio n. 5
0
def _all_rotations():
    for (
        pauli,
        flip,
    ) in itertools.product(_paulis, _bools):
        yield cirq.PauliTransform(pauli, flip)