Ejemplo n.º 1
0
 def circuit(p1, p2=y, **kwargs):
     qml.RX(p1, wires=0)
     qml.RY(p2[0] * p2[1], wires=1)
     qml.RX(kwargs["p3"], wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.expval(qml.PauliZ(0) @ qml.PauliX(1))
Ejemplo n.º 2
0
 def circuit(dummy1, array, dummy2):
     qml.RY(0.5 * array[0,1], wires=0)
     qml.RY(-0.5 * array[1,1], wires=0)
     return qml.expval(qml.PauliX(0))  # returns a scalar
Ejemplo n.º 3
0
 def circuit(dummy1, array, dummy2):
     qml.RY(0.5 * array[0,1], wires=0)
     qml.RY(-0.5 * array[1,1], wires=0)
     qml.RY(array[1,0], wires=1)
     return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliX(1))  # returns a 2-vector
Ejemplo n.º 4
0
 def func(x):
     qml.RY(x, wires=0)
     return state()
Ejemplo n.º 5
0
 def circuit(weights):
     qml.RX(weights[0], wires=0)
     qml.RY(weights[1], wires=0)
     qml.CNOT(wires=[0, 1])
     qml.PhaseShift(weights[2], wires=1)
     return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliX(1))
Ejemplo n.º 6
0
 def circuit(params, wires=None):
     qml.RX(params[0], wires=0)
     qml.RY(params[1], wires=0)
Ejemplo n.º 7
0
 def circuit(x, y, wires=0):
     qml.RX(x, wires=wires)
     qml.RY(y, wires=wires)
     return qml.expval(H)
Ejemplo n.º 8
0
# :math:`RY(\pi/2)` respectively, as well as the :math:`\sqrt{W}` gate,
# where :math:`W = \frac{X + Y}{2}`. The latter is easiest defined by its
# unitary matrix
#
# .. math::
#
#    \frac{1}{\sqrt{2}}
#    \begin{bmatrix}
#       1 & \sqrt{i}  \\
#       \sqrt{-i} & 1 \\
#    \end{bmatrix}.
#
# The :math:`\sqrt{X}` gate is already implemented in PennyLane, while the
# two other gates can be implemented as follows:

sqrtYgate = lambda wires: qml.RY(np.pi / 2, wires=wires)

sqrtWgate = lambda wires: qml.QubitUnitary(
    np.array([[1, -np.sqrt(1j)], [np.sqrt(-1j), 1]]) / np.sqrt(2), wires=wires)

single_qubit_gates = [qml.SX, sqrtYgate, sqrtWgate]

######################################################################
# For the two-qubit gates we need the iSWAP gate
#
# .. math::
#
#    \begin{bmatrix}
#       1 & 0 & 0 & 0 \\
#       0 & 0 & i & 0 \\
#       0 & i & 0 & 0 \\
Ejemplo n.º 9
0
 def circ(x, y):
     qml.RX(x, wires=0)
     qml.RY(y, wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 10
0
 def func(x, y):
     """My function docstring"""
     qml.RX(x, wires=0)
     qml.RY(y, wires=1)
     qml.CNOT(wires=[0, 1])
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 11
0
 def circuit(x):
     if x < 0:
         qml.RY(x, wires=0)
     else:
         qml.RZ(x, wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 12
0
 def circuit(p1, p2=y, **kwargs):
     qml.RX(p1, wires=0)
     qml.RY(p2[0] * p2[1], wires=1)
     qml.RX(kwargs["p3"], wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.probs(wires=0), qml.var(qml.PauliZ(1))
Ejemplo n.º 13
0
 def func(x, y):
     qml.RX(x, wires=0)
     qml.RY(y, wires=1)
     qml.CNOT(wires=[0, 1])
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 14
0
 def circuit(p1, p2=y, **kwargs):
     qml.RX(p1, wires=0)
     qml.RY(p2[0] * p2[1], wires=1)
     qml.RX(kwargs["p3"], wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.state()
Ejemplo n.º 15
0
 def circuit(a):
     qml.RY(a, wires=0)
     qml.RX(0.2, wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 16
0
 def circuit(param):
     qml.Hadamard(0)
     qml.CNOT(wires=[0, 1])
     qml.RY(param, wires=0)
     return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
Ejemplo n.º 17
0
 def circuit(params_0, params_1):
     qml.RX(params_0, wires=0)
     qml.RY(params_1, wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 18
0
 def circuit(a):
     qml.RY(a[0], wires=0)
     qml.RX(a[1], wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 19
0
 def circuit(params, wires=0):
     qml.RX(params[0], wires=wires)
     qml.RY(params[1], wires=wires)
Ejemplo n.º 20
0
 def circuit(x, y, z):
     qml.RY(x * z, wires=0)
     qml.RZ(y, wires=0)
     qml.RX(z + z**2 + tf.sin(a), wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 21
0
 def circuit(params):
     qml.RX(params[0], wires=0)
     qml.RY(params[1], wires=0)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 22
0
 def circuit(a, b):
     qml.RY(a, wires=0)
     qml.RX(b, wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
Ejemplo n.º 23
0
 def circuit(a, b, c):
     qml.RX(a, wires=0)
     qml.RY(b, wires=0)
     qml.CNOT(wires=[0, 1])
     qml.PhaseShift(c, wires=1)
     return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliX(1))
Ejemplo n.º 24
0
 def circuit(U, a):
     qml.QubitUnitary(U, wires=0)
     qml.RY(a, wires=0)
     return qml.expval(qml.PauliZ(0))
def U_c_dagger():
    """Adjoint of U_c."""
    qml.CNOT(wires=[ancilla_idx + 1, ancilla_idx])
    qml.CRY(2 * np.arctan(sqrt_c[2] / sqrt_c[1]),
            wires=[ancilla_idx, ancilla_idx + 1])
    qml.RY(2 * np.arccos(sqrt_c[0]), wires=ancilla_idx)
Ejemplo n.º 26
0
 def circuit(x, y):
     qml.RX(x, wires=[0])
     qml.RY(y, wires=[1])
     qml.CNOT(wires=[0, 1])
     return qml.probs(wires=[0]), qml.probs(wires=[1])
Ejemplo n.º 27
0
 def circuit(dummy1, array, dummy2):
     qml.RY(0.5 * array[0,1], wires=0)
     qml.RY(-0.5 * array[1,1], wires=0)
     return qml.expval(qml.PauliX(0)),  # note the comma, returns a 1-vector
Ejemplo n.º 28
0
 def circuit(x, y):
     qml.RX(x, wires=[0])
     qml.RY(y, wires=[1])
     qml.CNOT(wires=[0, 1])
     return [qml.expval(qml.PauliZ(0)), qml.probs(wires=[1])]
Ejemplo n.º 29
0
 def circuit(x, q=default_q):
     qml.RY(x, wires=0)
     return qml.expval(qml.PauliZ(q))
Ejemplo n.º 30
0
 def func(x, y):
     qml.RX(x, wires=0)
     qml.RY(y, wires=1)
     qml.CNOT(wires=[0, 1])
     return 5