Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def circuit(w, x=None):
qml.RX(w, wires=[0])
qml.RX(x, wires=[1])
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
def non_mutable_circuit(x, *, c=None):
qml.RX(x, wires=0)
qml.RX(c, wires=0)
return qml.expval(qml.PauliZ(0))
def circuit(x):
qml.RX(x, wires=[0])
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliX(0))
def circuit(a):
qml.RX(a, wires=0)
return qml.expval(qml.PauliX(0))
def circuit(x, y):
qml.RX(x, wires=[0])
qml.RY(y, wires=[1])
qml.CNOT(wires=[0, 1])
return qml.sample(qml.PauliZ(0) @ qml.PauliX(1))
def circuit(a):
qml.RX(a, wires=0)
return qml.expval(qml.PauliZ(wires=0))
def circuit_Zpl():
qml.RX(0.0, wires=qubit)
return qml.expval(qml.PauliZ(qubit))
varphi = -0.543
dev = device(3)
obs = (
qml.PauliZ(wires=[0], do_queue=False)
@ qml.Hadamard(wires=[1], do_queue=False)
@ qml.PauliY(wires=[2], do_queue=False)
)
with mimic_execution_for_var(dev):
dev.apply(
[
qml.RX(theta, wires=[0]),
qml.RX(phi, wires=[1]),
qml.RX(varphi, wires=[2]),
qml.CNOT(wires=[0, 1]),
qml.CNOT(wires=[1, 2]),
],
rotations=obs.diagonalizing_gates(),
)
res = dev.var(obs)
expected = (
3
+ np.cos(2 * phi) * np.cos(varphi) ** 2
- np.cos(2 * theta) * np.sin(varphi) ** 2
- 2 * np.cos(theta) * np.sin(phi) * np.sin(2 * varphi)
) / 4
assert np.allclose(res, expected, **tol)
def circuit4(a, b, c):
qml.RX(b, wires=0)
qml.RX(c, wires=1)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
def layer(params, j):
for i in range(nr_qubits):
qml.RX(params[i, j, 0], wires=i)
qml.RY(params[i, j, 1], wires=i)
qml.RZ(params[i, j, 2], wires=i)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[0, 2])
qml.CNOT(wires=[1, 2])