How to use the projectq.ops.Z function in projectq

To help you get started, we’ve selected a few projectq 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 Huawei-HiQ / HiQsimulator / examples / exactgrover_mpi.py View on Github external
oracle_out = eng.allocate_qubit()
    X | oracle_out
    H | oracle_out

    # run num_it iterations
    with Loop(eng, num_it):
        # oracle adds a (-1)-phase to the solution
        oracle(eng, x, oracle_out)

        # reflection across uniform superposition
        with Compute(eng):
            All(H) | x
            All(X) | x

        with Control(eng, x[0:-1]):
            Z | x[-1]

        Uncompute(eng)
   
    # prepare the oracle output qubit (the one that is flipped to indicate the
    # solution. start in state |1> s.t. a bit-flip turns into a e^(i*phi)-phase. 
    H | oracle_out
    oracle_modified(eng, x, oracle_out, phi)
    
    with Compute(eng):
        All(H) | x
        All(X) | x

    with Control(eng, x[0:-1]):
        Rz(varphi) | x[-1]
        Ph(varphi/2) | x[-1]
github ProjectQ-Framework / ProjectQ / examples / grover.py View on Github external
oracle_out = eng.allocate_qubit()
    X | oracle_out
    H | oracle_out

    # run num_it iterations
    with Loop(eng, num_it):
        # oracle adds a (-1)-phase to the solution
        oracle(eng, x, oracle_out)

        # reflection across uniform superposition
        with Compute(eng):
            All(H) | x
            All(X) | x

        with Control(eng, x[0:-1]):
            Z | x[-1]

        Uncompute(eng)

    All(Measure) | x
    Measure | oracle_out

    eng.flush()
    # return result
    return [int(qubit) for qubit in x]
github QuantumBFS / Yao.jl / benchmark / projectq / bench.py View on Github external
def repeatxyz(self):
        tl = []
        for nsite, num_bench in zip(NL, [1000, 1000, 1000, 100, 10, 5]):
            print('========== N: %d ============'%nsite)
            for func in [bRG(ops.X), bRG(ops.Y), bRG(ops.Z)]:
                tl.append(qbenchmark(func, nsite, num_bench)*1e6)
        np.savetxt('repeatxyz-report.dat', tl)
github QuantumBFS / Yao.jl / benchmark / projectq / bench.py View on Github external
def cxyz(self):
        tl = []
        for nsite, num_bench in zip(NL, [1000, 1000, 1000, 100, 10, 5]):
            print('========== N: %d ============'%nsite)
            for func in [bCG(ops.X), bCG(ops.Y), bCG(ops.Z)]:
                tl.append(qbenchmark(func, nsite, num_bench)*1e6)
        np.savetxt('cxyz-report.dat', tl)
github quantumlib / OpenFermion-ProjectQ / openfermionprojectq / _ffft.py View on Github external
def fourier_transform_0(register, mode_a, mode_b):
    """Apply the fermionic Fourier transform to two modes.

    The fermionic Fourier transform is applied to the qubits
    corresponding to mode_a and mode_b, , after the Jordan-Wigner

    Args:
        register (projectq.Qureg): The register of qubits to act on.
        mode_a, mode_b (int): The two modes to Fourier transform.
    """
    operator = fourier_transform_0_generator(mode_a, mode_b)
    jw_operator = jordan_wigner(operator)
    Z | register[mode_b]
    TimeEvolution(numpy.pi / 8., jw_operator) | register
github ProjectQ-Framework / ProjectQ / projectq / backends / _circuits / _to_latex.py View on Github external
self.pos[l] = pos + self._gate_pre_offset(gate)

            connections = ""
            for l in all_lines:
                connections += self._line(self.op_count[l] - 1,
                                          self.op_count[l],
                                          line=l)
            add_str = ""
            if gate == X:
                # draw NOT-gate with controls
                add_str = self._x_gate(lines, ctrl_lines)
                # and make the target qubit quantum if one of the controls is
                if not self.is_quantum[lines[0]]:
                    if sum([self.is_quantum[i] for i in ctrl_lines]) > 0:
                        self.is_quantum[lines[0]] = True
            elif gate == Z and len(ctrl_lines) > 0:
                add_str = self._cz_gate(lines + ctrl_lines)
            elif gate == Swap:
                add_str = self._swap_gate(lines, ctrl_lines)
            elif gate == SqrtSwap:
                add_str = self._sqrtswap_gate(lines,
                                              ctrl_lines,
                                              daggered=False)
            elif gate == get_inverse(SqrtSwap):
                add_str = self._sqrtswap_gate(lines, ctrl_lines, daggered=True)
            elif gate == Measure:
                # draw measurement gate
                for l in lines:
                    op = self._op(l)
                    width = self._gate_width(Measure)
                    height = self._gate_height(Measure)
                    shift0 = .07 * height
github ProjectQ-Framework / ProjectQ / examples / teleport.py View on Github external
if verbose:
        print("Alice entangled her qubit with her share of the Bell-pair.")

    # measure two values (once in Hadamard basis) and send the bits to Bob
    H | psi
    Measure | (psi, b1)
    msg_to_bob = [int(psi), int(b1)]
    if verbose:
        print("Alice is sending the message {} to Bob.".format(msg_to_bob))

    # Bob may have to apply up to two operation depending on the message sent
    # by Alice:
    with Control(eng, b1):
        X | b2
    with Control(eng, psi):
        Z | b2

    # try to uncompute the psi state
    if verbose:
        print("Bob is trying to uncompute the state.")
    with Dagger(eng):
        state_creation_function(eng, b2)

    # check whether the uncompute was successful. The simulator only allows to
    # delete qubits which are in a computational basis state.
    del b2
    eng.flush()

    if verbose:
        print("Bob successfully arrived at |0>")
github Huawei-HiQ / HiQsimulator / examples / teleport_mpi.py View on Github external
CNOT | (psi, b1)
    print("= Step 2. Alice entangles the state with her share of the Bell-pair")

    # measure two values (once in Hadamard basis) and send the bits to Bob
    H | psi
    Measure | psi
    Measure | b1
    msg_to_bob = [int(psi), int(b1)]
    print("= Step 3. Alice sends the classical message {} to Bob".format(msg_to_bob))

    # Bob may have to apply up to two operation depending on the message sent
    # by Alice:
    with Control(eng, b1):
        X | b2
    with Control(eng, psi):
        Z | b2

    # try to uncompute the psi state
    print("= Step 4. Bob tries to recover the state created by Alice")
    with Dagger(eng):
        state_creation_function(eng, b2)

    # check whether the uncompute was successful. The simulator only allows to
    # delete qubits which are in a computational basis state.
    del b2
    eng.flush()

    print("\t Bob successfully arrived at |0>")
github quantumlib / OpenFermion-ProjectQ / openfermionprojectq / _ffft.py View on Github external
def fourier_transform_0_adjacent(register, mode):
    """Apply the fermionic Fourier transform to two adjacent modes.

    The fermionic Fourier transform is applied to the qubits
    corresponding to mode and mode + 1 after the Jordan-Wigner
    transformation.

    Args:
        register (projectq.Qureg): The register of qubits to act on.
        mode (int): The lower of the two modes to Fourier transform.
    """
    jw_operator = (QubitOperator(((mode, 'X'), (mode + 1, 'Y'))) -
                   QubitOperator(((mode, 'Y'), (mode + 1, 'X'))))
    Z | register[mode + 1]
    TimeEvolution(numpy.pi / 8., jw_operator) | register