How to use the projectq.ops.Ry 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 / SymMatrixSolver_mpi.py View on Github external
for j in range(2**n):
            for k in range(n):
                if j%(2**k)==0:
                    X | Qubits[n-k-1]
                    XNum+=2
            with Control(eng,Qubits[0:n]):
                X | Qubits[n+j]
                CNXNum+=2
    
    # Control Ry
    for i in range(2**n):
        with Control(eng,Qubits[n+i]):
            #theta=(1/Array[i])/(2**r)
            theta=2*math.asin(1/Array[i])
            #theta=(2/Array[2**n-i-1]/max(Array))/(2**r)
            Ry(theta) | Qubits[-1]
            CRyNum+=1
            
    Uncompute(eng)
    eng.flush()
    
    for i in range(2**n):
        state=np.zeros(n)
        x=i
        for j in range(n):
            if 2**(n-j-1)>x:
                state[j]=0
            else:
                state[j]=1
                x-=2**(n-j-1)
        # Change the list of states to string format
        StrState=''
github Huawei-HiQ / HiQsimulator / examples / SymMatrixSolver_mpi.py View on Github external
n=para()[0]
    Matrix=para()[1]
    Array=para()[2]
    XNum=0
    RyNum=0
    HNum=0
    CNXNum=0
    CRyNum=0
    r=30
    Qubits=eng.allocate_qureg(n+2**n+1)
    States0=np.zeros(2**n)
    Statest=np.zeros(2**n)
    # Initial state papreparation
    for i in range(n):
        random.seed(i*7)
        Ry(random.randint(1,300)/23) | Qubits[i]
        #Ry(2) | Qubits[i]
        RyNum+=1
    eng.flush()
    #Output the initial state
    for i in range(2**n):
        state=np.zeros(n)
        x=i
        for j in range(n):
            if 2**(n-j-1)>x:
                state[j]=0
            else:
                state[j]=1
                x-=2**(n-j-1)
        # Change the list of states to string format
        StrState=''
        for k in range(n):
github Huawei-HiQ / HiQsimulator / examples / ToeplitzSimplify_constant.py View on Github external
def randb(eng,n,Qubits):  
    for i in range(n):
        #random.seed(i*8)
        Ry(-1*random.randint(1,100)/23) | Qubits[i]
# =============================================================================
github ProjectQ-Framework / ProjectQ / projectq / setups / decompositions / time_evolution.py View on Github external
assert len(hamiltonian.terms) == 1
    term = list(hamiltonian.terms)[0]
    coefficient = hamiltonian.terms[term]
    check_indices = set()

    # Check that hamiltonian is not identity term,
    # Previous __or__ operator should have apply a global phase instead:
    assert not term == ()

    # hamiltonian has only a single local operator
    if len(term) == 1:
        with Control(eng, cmd.control_qubits):
            if term[0][1] == 'X':
                Rx(time * coefficient * 2.) | qureg[term[0][0]]
            elif term[0][1] == 'Y':
                Ry(time * coefficient * 2.) | qureg[term[0][0]]
            else:
                Rz(time * coefficient * 2.) | qureg[term[0][0]]
    # hamiltonian has more than one local operator
    else:
        with Control(eng, cmd.control_qubits):
            with Compute(eng):
                # Apply local basis rotations
                for index, action in term:
                    check_indices.add(index)
                    if action == 'X':
                        H | qureg[index]
                    elif action == 'Y':
                        Rx(math.pi / 2.) | qureg[index]
                # Check that qureg had exactly as many qubits as indices:
                assert check_indices == set((range(len(qureg))))
                # Compute parity
github Qiskit / qiskit-terra / qiskit / backends / local / qasm_simulator_projectq.py View on Github external
for operation in ccircuit['operations']:
                if 'conditional' in operation:
                    mask = int(operation['conditional']['mask'], 16)
                    if mask > 0:
                        value = self._classical_state & mask
                        while (mask & 0x1) == 0:
                            mask >>= 1
                            value >>= 1
                        if value != int(operation['conditional']['val'], 16):
                            continue
                # Check if single  gate
                if operation['name'] in ['U', 'u3']:
                    params = operation['params']
                    qubit = qureg[operation['qubits'][0]]
                    Rz(params[2]) | qubit
                    Ry(params[0]) | qubit
                    Rz(params[1]) | qubit
                elif operation['name'] in ['u1']:
                    params = operation['params']
                    qubit = qureg[operation['qubits'][0]]
                    Rz(params[0]) | qubit
                elif operation['name'] in ['u2']:
                    params = operation['params']
                    qubit = qureg[operation['qubits'][0]]
                    Rz(params[1] - np.pi/2) | qubit
                    Rx(np.pi/2) | qubit
                    Rz(params[0] + np.pi/2) | qubit
                elif operation['name'] == 't':
                    qubit = qureg[operation['qubits'][0]]
                    T | qubit
                elif operation['name'] == 'h':
                    qubit = qureg[operation['qubits'][0]]
github quantumlib / OpenFermion-ProjectQ / openfermionprojectq / _low_depth_trotter_simulation.py View on Github external
def special_F_adjacent(register, qubit_index, xx_yy_angle, zz_angle):
    """Apply the 'special F' (fermionic swap, XX+YY evolution, and ZZ
    evolution) gate to the register on qubit_index and qubit_index + 1.

    Args:
        register (projectq.QuReg): The register to apply the gate to.
        qubit_index (integer): The left qubit to act on.
        xx_yy_angle (float): The angle for evolution under XX+YY.
        zz_angle (float): The angle for evolution under ZZ.
    """
    Rx(numpy.pi / 2.) | register[qubit_index]
    CNOT | (register[qubit_index], register[qubit_index + 1])
    if numpy.abs(xx_yy_angle) > 0.0:
        Rx(xx_yy_angle) | register[qubit_index]
        Ry(xx_yy_angle) | register[qubit_index + 1]
    CNOT | (register[qubit_index + 1], register[qubit_index])
    Rx(-numpy.pi / 2.) | register[qubit_index + 1]
    if numpy.abs(zz_angle) > 0.0:
        Rz(zz_angle) | register[qubit_index + 1]
    Sdag | register[qubit_index + 1]
    CNOT | (register[qubit_index], register[qubit_index + 1])
    S | register[qubit_index]
    S | register[qubit_index + 1]
github XanaduAI / pennylane-pq / pennylane_pq / pqops.py View on Github external
def __or__(self, qubits):
        pq.ops.Rz(self.angles[0]) | qubits #pylint: disable=expression-not-assigned
        pq.ops.Ry(self.angles[1]) | qubits #pylint: disable=expression-not-assigned
        pq.ops.Rz(self.angles[2]) | qubits #pylint: disable=expression-not-assigned
github ProjectQ-Framework / FermiLib / src / fermilib / circuits / _low_depth_trotter_simulation.py View on Github external
def special_F_adjacent(register, qubit_index, xx_yy_angle, zz_angle):
    """Apply the 'special F' (fermionic swap, XX+YY evolution, and ZZ
    evolution) gate to the register on qubit_index and qubit_index + 1.

    Args:
        register (projectq.QuReg): The register to apply the gate to.
        qubit_index (integer): The left qubit to act on.
        xx_yy_angle (float): The angle for evolution under XX+YY.
        zz_angle (float): The angle for evolution under ZZ.
    """
    Rx(numpy.pi / 2.) | register[qubit_index]
    CNOT | (register[qubit_index], register[qubit_index + 1])
    Rx(xx_yy_angle) | register[qubit_index]
    Ry(xx_yy_angle) | register[qubit_index + 1]
    CNOT | (register[qubit_index + 1], register[qubit_index])
    Rx(-numpy.pi / 2.) | register[qubit_index + 1]
    Rz(zz_angle) | register[qubit_index + 1]
    Sdag | register[qubit_index + 1]
    CNOT | (register[qubit_index], register[qubit_index + 1])
    S | register[qubit_index]
    S | register[qubit_index + 1]
github SoftwareQuTech / SimulaQron / simulaqron / virtNode / projectQSimulator.py View on Github external
"""
        Applies a rotation around the axis n with the angle a to qubit with number qubitNum. If n is zero a ValueError
        is raised.

        :param qubitNum: int
            Qubit number
        :param n: tuple of floats
            A tuple of three numbers specifying the rotation axis, e.g n=(1,0,0)
        :param a: float
            The rotation angle in radians.
        """
        n = tuple(n)
        if n == (1, 0, 0):
            self.apply_onequbit_gate(pQ.ops.Rx(a), qubitNum)
        elif n == (0, 1, 0):
            self.apply_onequbit_gate(pQ.ops.Ry(a), qubitNum)
        elif n == (0, 0, 1):
            self.apply_onequbit_gate(pQ.ops.Rz(a), qubitNum)
        else:
            raise NotImplementedError("Can only do rotations around X, Y, or Z axis right now")