Beispiel #1
0
def test_gate_from_info():
    assert (_rotations._ROTATION_GATE_FROM_INFO["X"](cmath.pi / 4) == gates.Rx(
        cmath.pi / 4))
    assert (_rotations._ROTATION_GATE_FROM_INFO["Y"](cmath.pi / 2) == gates.Ry(
        cmath.pi / 2))
    assert (_rotations._ROTATION_GATE_FROM_INFO["Z"](cmath.pi) == gates.Rz(
        cmath.pi))
    return
Beispiel #2
0
def test_single_rotation2():
    commands = GetCommand()
    eng = projectq.MainEngine(engine_list=[commands])
    qubit1 = eng.allocate_qubit()
    qubit2 = eng.allocate_qubit()

    gates.CNOT | (qubit1, qubit2)
    gates.Rz(1) | qubit2
    cmd2_info = [[(0, "Z")], "pi4", 1]

    permute_cnot(commands.commands[0], commands.commands[1], cmd2_info)

    print(cmd2_info)
    assert (len(cmd2_info[0]) == 2)
    assert (cmd2_info[0][1][1] == "Z")
Beispiel #3
0
    def visit_R(self, node, params):
        # type parameter
        t = params[0]
        typ = round(float(t))
        # other params
        angle = params[2]
        q = params[4]

        # different angle convention
        angle = -angle

        # differentiate with type
        if typ == 1:
            return (ops.Rx(angle), (q, ))
        elif typ == 2:
            return (ops.Ry(angle), (q, ))
        elif typ == 3:
            return (ops.Rz(angle), (q, ))
        else:
            raise InvalidRotationGateError
Beispiel #4
0
def test_gate_to_info():
    gate = gates.Rx(cmath.pi / 4)
    info = _rotations._ROTATION_GATE_TO_INFO[type(gate)](gate)
    assert (info[:2] == [[(0, "X")], "pi4"])
    assert (abs(info[2] - (cmath.pi / 4)) < _PRECISION)

    gate = gates.Ry(cmath.pi / 2)
    info = _rotations._ROTATION_GATE_TO_INFO[type(gate)](gate)
    assert (info[:2] == [[(0, "Y")], "pi2"])
    assert (abs(info[2] - (cmath.pi / 2)) < _PRECISION)

    gate = gates.Rz(cmath.pi)
    info = _rotations._ROTATION_GATE_TO_INFO[type(gate)](gate)
    assert (info[:2] == [[(0, "Z")], "pi"])
    assert (abs(info[2] - (cmath.pi)) < _PRECISION)

    gate = gates.TimeEvolution(-cmath.pi / 8, gates.QubitOperator("X0 X1 Y2"))
    info = _rotations._ROTATION_GATE_TO_INFO[type(gate)](gate)
    assert (info[:2] == [[(0, "X"), (1, "X"), (2, "Y")], "pi4"])
    assert (abs(info[2] - (cmath.pi / 4)) < _PRECISION)
    return
def test_Rz(benchmark, nbit):
    run_bench(benchmark, ops.Rz(0.5), 2, nbit)
Beispiel #6
0
_ROTATION_GATE_TO_INFO = {
	gates.XGate: lambda gate: [[(0,"X")], "pi", cmath.pi],
	gates.YGate: lambda gate: [[(0,"Y")], "pi", cmath.pi],
	gates.ZGate: lambda gate: [[(0,"Z")], "pi", cmath.pi],
	gates.SGate: lambda gate: [[(0,"Z")], "pi2", cmath.pi/2],
	gates.TGate: lambda gate: [[(0,"Z")], "pi4", cmath.pi/4],
	gates.Rx: lambda gate: [[(0,"X")]] + determine_rotation(gate),
	gates.Ry: lambda gate: [[(0,"Y")]] + determine_rotation(gate),
	gates.Rz: lambda gate: [[(0,"Z")]] + determine_rotation(gate),
	gates.TimeEvolution: lambda gate: time_evolution_info(gate),
}

_ROTATION_GATE_FROM_INFO = {
	"X" : lambda angle: gates.Rx(angle),
	"Y" : lambda angle: gates.Ry(angle),
	"Z" : lambda angle: gates.Rz(angle)
}



#
# This lookup table implemets the following commutation relations relation
# (1) P * P'(phi) = P'(phi) * P
# (2) P'(phi) * P = P * P'(-phi)
# (3) P(pi/2) * P'(phi) = (i P P')(phi) * P(pi/2)
# (4) P'(phi) * P(pi/2) = P(pi/2) * (i P P')(-phi)
# 
# Here, P and P' are bases for one of the Pauli-rotations (Rx, Ry, Rz).
# The angle pi/2 indicates S gates, phi is arbitrary and if the angle is omitted,
# a standard Pauli operator (angle = pi) is used.
#
Beispiel #7
0
def test_Rz(benchmark, nqubits):
    benchmark.group = "Rz"
    run_bench(benchmark, ops.Rz(0.5), 2, nqubits)
def PrepareState(qubits, inputValue):
    ops.Rx(inputValue['theta']) | qubits[0]
    ops.Rz(inputValue['phi']) | qubits[0]
import projectq.ops as ops
import numpy as np
np.set_printoptions(precision=2)

# create a main compiler engine
drawing_engine = CircuitDrawer()
eng = MainEngine(drawing_engine)

a = eng.allocate_qubit()
b = eng.allocate_qubit()
c = eng.allocate_qubit()

pi = 3.14
mpi = -3.14

ops.Rz(pi/2) | a
ops.Rx(pi/2) | a
ops.Rx(mpi) | b
ops.C(ops.Z) | (b, a)
ops.Rz(pi/2) | c
ops.Rx(pi/2) | c
ops.C(ops.Z) | (b, c)
ops.Rz(mpi/2) | a
ops.Rz(mpi/2) | b
ops.Rx(mpi/2) | b
ops.Rz(pi/2) | b
ops.Rz(mpi/2) | c


eng.flush()
print(drawing_engine.get_latex())
# written by Ryan LaRose <*****@*****.**>
# at Michigan State University 05-22-18
# ==========================================================

from projectq import MainEngine
from projectq.backends import CircuitDrawer
import projectq.ops as ops


# create a main compiler engine
drawing_engine = CircuitDrawer()
eng = MainEngine(drawing_engine)

q = eng.allocate_qureg(3)

ops.Rz(3.14/2) | q[2]
ops.Rx(3.14/2) | q[2]
ops.Rz(3.14/2) | q[2]

ops.CX | (q[1], q[0])

ops.Rz(3.14/2) | q[1]
ops.Rx(3.14/2) | q[1]
ops.Rz(3.14/2) | q[1]

ops.Rz(3.14/2) | q[0]
ops.Rx(3.14/2) | q[0]
ops.Rz(3.14/2) | q[0]

ops.CX | (q[1], q[0])