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))
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
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
def func(x): qml.RY(x, wires=0) return state()
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))
def circuit(params, wires=None): qml.RX(params[0], wires=0) qml.RY(params[1], wires=0)
def circuit(x, y, wires=0): qml.RX(x, wires=wires) qml.RY(y, wires=wires) return qml.expval(H)
# :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 \\
def circ(x, y): qml.RX(x, wires=0) qml.RY(y, wires=0) return qml.expval(qml.PauliZ(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))
def circuit(x): if x < 0: qml.RY(x, wires=0) else: qml.RZ(x, wires=0) return qml.expval(qml.PauliZ(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))
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))
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()
def circuit(a): qml.RY(a, wires=0) qml.RX(0.2, wires=0) return qml.expval(qml.PauliZ(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))
def circuit(params_0, params_1): qml.RX(params_0, wires=0) qml.RY(params_1, wires=0) return qml.expval(qml.PauliZ(0))
def circuit(a): qml.RY(a[0], wires=0) qml.RX(a[1], wires=0) return qml.expval(qml.PauliZ(0))
def circuit(params, wires=0): qml.RX(params[0], wires=wires) qml.RY(params[1], wires=wires)
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))
def circuit(params): qml.RX(params[0], wires=0) qml.RY(params[1], wires=0) return qml.expval(qml.PauliZ(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))
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))
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)
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])
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
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])]
def circuit(x, q=default_q): qml.RY(x, wires=0) return qml.expval(qml.PauliZ(q))
def func(x, y): qml.RX(x, wires=0) qml.RY(y, wires=1) qml.CNOT(wires=[0, 1]) return 5