How to use the cirq.Z function in cirq

To help you get started, we’ve selected a few cirq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quantumlib / Cirq / examples / hhl.py View on Github external
memory = cirq.GridQubit(register_size+1, 0)

    c = cirq.Circuit()
    hs = HamiltonianSimulation(A, t)
    pe = PhaseEstimation(register_size+1, hs)
    c.append([gate(memory) for gate in input_prep_gates])
    c.append([
        pe(*(register + [memory])),
        EigenRotation(register_size+1, C, t)(*(register+[ancilla])),
        pe(*(register + [memory]))**-1,
        cirq.measure(ancilla)
    ])

    # Pauli observable display
    c.append([
        cirq.approx_pauli_string_expectation(cirq.Z(ancilla),
                                             num_samples=5000,
                                             key='a'),
        cirq.approx_pauli_string_expectation(cirq.X(memory),
                                             num_samples=5000,
                                             key='x'),
        cirq.approx_pauli_string_expectation(cirq.Y(memory),
                                             num_samples=5000,
                                             key='y'),
        cirq.approx_pauli_string_expectation(cirq.Z(memory),
                                             num_samples=5000,
                                             key='z'),
    ])

    return c
github quantumlib / Cirq / dev_tools / profiling / benchmark_simulators.py View on Github external
""""Runs the simulator."""
    circuit = cirq.Circuit(device=test_device)

    for _ in range(num_gates):
        which = np.random.choice(['expz', 'expw', 'exp11'])
        if which == 'expw':
            q1 = cirq.GridQubit(0, np.random.randint(num_qubits))
            circuit.append(
                cirq.PhasedXPowGate(
                    phase_exponent=np.random.random(),
                    exponent=np.random.random()
                ).on(q1))
        elif which == 'expz':
            q1 = cirq.GridQubit(0, np.random.randint(num_qubits))
            circuit.append(
                cirq.Z(q1)**np.random.random())
        elif which == 'exp11':
            q1 = cirq.GridQubit(0, np.random.randint(num_qubits - 1))
            q2 = cirq.GridQubit(0, q1.col + 1)
            circuit.append(cirq.CZ(q1, q2)**np.random.random())
    circuit.append([
        cirq.measure(cirq.GridQubit(0, np.random.randint(num_qubits)),
                     key='meas')
    ])

    if sim_type == _UNITARY:
        circuit.final_wavefunction(initial_state=0)
    elif sim_type == _DENSITY:
        cirq.DensityMatrixSimulator().run(circuit)
github quantumlib / OpenFermion-Cirq / openfermioncirq / gates / common_gates.py View on Github external
def _decompose_(self, qubits):
        a, b = qubits
        yield cirq.Z(a) ** -0.5
        yield XXYY(a, b) ** self.exponent
        yield cirq.Z(a) ** 0.5
github quantumlib / OpenFermion-Cirq / openfermioncirq / primitives / bogoliubov_transform.py View on Github external
def _ops_from_givens_rotations_circuit_description(
        qubits: Sequence[cirq.Qid],
        circuit_description: Iterable[Iterable[
            Union[str, Tuple[int, int, float, float]]]]) -> cirq.OP_TREE:
    """Yield operations from a Givens rotations circuit obtained from
    OpenFermion.
    """
    for parallel_ops in circuit_description:
        for op in parallel_ops:
            if op == 'pht':
                yield cirq.X(qubits[-1])
            else:
                i, j, theta, phi = cast(Tuple[int, int, float, float], op)
                yield Ryxxy(theta).on(qubits[i], qubits[j])
                yield cirq.Z(qubits[j]) ** (phi / numpy.pi)
github quantumlib / Cirq / examples / bcs_mean_field.py View on Github external
def fswap(p, q):
    """Decompose the Fermionic SWAP gate into two single-qubit gates and
    one iSWAP gate.

    Args:
        p: the id of the first qubit
        q: the id of the second qubit
    """

    yield cirq.ISWAP(q, p), cirq.Z(p) ** 1.5
    yield cirq.Z(q) ** 1.5
github gecrooks / quantumflow-dev / quantumflow / xcirq.py View on Github external
T:      cirq.T,
        H:      cirq.H,
        CNOT:   cirq.CNOT,
        CZ:     cirq.CZ,
        SWAP:   cirq.SWAP,
        ISWAP:  cirq.ISWAP,
        CCZ:    cirq.CCZ,
        CCNOT:  cirq.CCX,
        CSWAP:  cirq.CSWAP,
    }

    # TODO: TH -> cirq.ops.HPowGate,
    turn_gates = {
        TX:     cirq.X,
        TY:     cirq.Y,
        TZ:     cirq.Z,
        XX:     cirq.XX,
        YY:     cirq.YY,
        ZZ:     cirq.ZZ,
    }

    for op in circ:
        qbs = [qubit_map[qb] for qb in op.qubits]

        if type(op) in operations:
            cqc.append(operations[type(op)].on(*qbs))
        elif type(op) in turn_gates:
            t = op.params['t']
            cqc.append(turn_gates[type(op)](*qbs) ** t)
        elif isinstance(op, IDEN):
            gate = cirq.IdentityGate(op.qubit_nb).on(*qbs)
            cqc.append(gate)
github quantumlib / Cirq / examples / bcs_mean_field.py View on Github external
[0  1/√2  -1/√2   0],
    [0  0      0     -1]
    The square root of the iSWAP gate is:
    [1, 0, 0, 0],
    [0, 0.5 + 0.5j, 0.5 - 0.5j, 0],
    [0, 0.5 - 0.5j, 0.5 + 0.5j, 0],
    [0, 0, 0, 1]

    Args:
        p: the first qubit
        q: the second qubit
    """

    yield cirq.Z(p)**1.5
    yield cirq.ISWAP(q, p)**0.5
    yield cirq.Z(p)**1.5