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(a, b, c):
qml.RX(a, wires=0)
qml.RY(b, wires=1)
with pu.OperationRecorder() as recorder:
ops = [
qml.PauliY(0),
qml.PauliY(1),
qml.RZ(c, wires=0),
qml.RZ(c, wires=1),
qml.CNOT(wires=[0, 1]),
]
assert str(recorder) == expected_output
assert recorder.queue == ops
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
def circuit(x, y, z):
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
def custom_fixed_ansatz(*params, wires=None):
"""Custom fixed ansatz"""
qml.RX(0.5, wires=0)
qml.RX(-1.2, wires=1)
qml.Hadamard(wires=0)
qml.CNOT(wires=[0, 1])
qml.Hadamard(wires=1)
qml.CNOT(wires=[0, 1])
def ansatz(x, y, z):
qml.QubitStateVector(np.array([1, 0, 1, 1]) / np.sqrt(3), wires=[0, 1])
qml.Rot(x, y, z, wires=0)
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0))
def ansatz(x, y, z):
qml.QubitStateVector(np.array([1, 0, 1, 1])/np.sqrt(3), wires=[0, 1])
qml.Rot(x, y, z, wires=0)
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
def test_supports_observable_exception(self, mock_device):
"""check that device.supports_observable raises proper errors
if the argument is of the wrong type"""
with pytest.raises(
ValueError,
match="The given observable must either be a pennylane.Observable class or a string.",
):
mock_device.supports_observable(3)
operation = qml.CNOT
with pytest.raises(
ValueError,
match="The given observable must either be a pennylane.Observable class or a string.",
):
mock_device.supports_observable(operation)
def circuit(param, fixed=None):
qml.RX(fixed, wires=0)
qml.RX(param, wires=1)
qml.CNOT(wires=[0, 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])
def test_CX(benchmark, nqubits):
benchmark.group = "CNOT"
gate_test = GateTest(nqubits, qml.CNOT, [0, 1])
benchmark(gate_test)
def CA_all():
"""Controlled application of all the unitary components A_l of the problem matrix A."""
# Controlled-A_1
qml.CNOT(wires=[ancilla_idx, 0])
qml.CZ(wires=[ancilla_idx, 1])
# Controlled-A2
qml.CNOT(wires=[ancilla_idx + 1, 0])