How to use the projectq.meta.Uncompute 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 QuTech-Delft / quantuminspire / docs / example_projectq_grover.py View on Github external
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 Huawei-HiQ / HiQsimulator / examples / maximum_search_constant_mpi.py View on Github external
H | oracle_out
             
        #run j iterations
        with Loop(eng, j):
            # oracle adds a (-1)-phase to the solution
            oracle(eng, x, Dataset,threshold, 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
         
        #read the measure value 
        k=0
        xvalue=0
        while kthreshold:
            return xvalue
        m=m*landa
        i=i+1
github ProjectQ-Framework / ProjectQ / examples / grover.py View on Github external
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 Huawei-HiQ / HiQsimulator / examples / exactgrover_mpi.py View on Github external
"""
    Marks the solution string 0,1,0,... by applying phase gate to the output bits,
    conditioned on qubits being equal to the alternating bit-string.

    Args:
        eng (MainEngine): Main compiler engine the algorithm is being run on.
        qubits (Qureg): n-qubit quantum register Grover search is run on.
        output (Qubit): Output qubit to mark the solution by a phase gate with parameter phi.
    """
    with Compute(eng):
        All(X) | qubits[1::2]
    with Control(eng, qubits):
        Rz(phi) | output
        Ph(phi/2) | output

    Uncompute(eng)
github Huawei-HiQ / HiQsimulator / examples / unknown_num_search_constant_mpi.py View on Github external
H | oracle_out
             
        #run j iterations
        with Loop(eng, j):
            # oracle adds a (-1)-phase to the solution
            oracle(eng, x, Dataset,threshold, 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
         
        #read the measure value 
        k=0
        xvalue=0
        while kthreshold:
            return xvalue
        m=m*landa
        i=i+1
github Huawei-HiQ / HiQsimulator / examples / exactgrover_mpi.py View on Github external
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]

    Uncompute(eng)
    
    All(Measure) | x
    Measure | oracle_out

    eng.flush()
    # return result
    return [int(qubit) for qubit in x]
github ProjectQ-Framework / ProjectQ / projectq / setups / decompositions / rx2rz.py View on Github external
def _decompose_rx(cmd):
    """ Decompose the Rx gate."""
    qubit = cmd.qubits[0]
    eng = cmd.engine
    angle = cmd.gate.angle

    with Control(eng, cmd.control_qubits):
        with Compute(eng):
            H | qubit
        Rz(angle) | qubit
        Uncompute(eng)
github Huawei-HiQ / HiQsimulator / examples / exactgrover_mpi.py View on Github external
"""
    Marks the solution string 0, 1, 0,...,0 by flipping the 
    
    qubit,
    conditioned on qubits being equal to the alternating bit-string.

    Args:
        eng (MainEngine): Main compiler engine the algorithm is being run on.
        qubits (Qureg): n-qubit quantum register Grover search is run on.
        output (Qubit): Output qubit to flip in order to mark the solution.
    """
    with Compute(eng):
        X | qubits[1]
    with Control(eng, qubits):
        X | output
    Uncompute(eng)