Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
decomposition."""
class DummyOp(qml.operation.Operation):
"""Dummy operation"""
num_params = 0
num_wires = 1
par_domain = "R"
grad_method = "A"
@staticmethod
def decomposition(wires=None):
ops = [qml.Hadamard(wires=wires)]
return ops
queue = [
qml.Rot(0, 1, 2, wires=0),
DummyOp(wires=0),
qml.RX(6, wires=0)
]
with pytest.raises(qml.DeviceError, match="DummyOp not supported on device"):
decompose_queue(queue, operable_mock_device_2_wires)
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 test_parameters_available_at_pre_measure(self, mock_device, monkeypatch):
"""Tests that the parameter mapping is available when pre_measure is called and that accessing
Device.parameters raises no error"""
p0 = 0.54
p1 = -0.32
queue = [
qml.RX(p0, wires=0),
qml.PauliY(wires=1),
qml.Rot(0.432, 0.123, p1, wires=2),
]
parameters = {0: (0, 0), 1: (2, 3)}
observables = [
qml.expval(qml.PauliZ(0)),
qml.var(qml.PauliZ(1)),
qml.sample(qml.PauliZ(2)),
]
p_mapping = {}
with monkeypatch.context() as m:
m.setattr(Device, "pre_measure", lambda self: p_mapping.update(self.parameters))
mock_device.execute(queue, observables, parameters=parameters)
def ansatz(var):
qml.Rot(0.3, 1.8, 5.4, wires=1)
qml.RX(var[0], wires=0)
qml.RY(var[1], wires=1)
qml.CNOT(wires=[0, 1])
def layer(W):
qml.Rot(W[0, 0], W[0, 1], W[0, 2], wires=0)
qml.Rot(W[1, 0], W[1, 1], W[1, 2], wires=1)
qml.CNOT(wires=[0, 1])
def real(angles, **kwargs):
qml.Hadamard(wires=0)
qml.Rot(*angles, wires=0)
def circuit0(params, x=None):
for i in range(n_wires):
qml.RX(x[i % n_features], wires=i)
qml.Rot(*params[1, 0, i], wires=i)
qml.CZ(wires=[1, 0])
qml.CZ(wires=[1, 2])
qml.CZ(wires=[3, 0])
for i in range(n_wires):
qml.Rot(*params[1, 1, i], wires=i)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.expval(qml.PauliZ(2))
def layer(W):
""" Single layer of the variational classifier.
Args:
W: array of variables
"""
qml.Rot(W[0, 0], W[0, 1], W[0, 2], wires=0)
qml.Rot(W[1, 0], W[1, 1], W[1, 2], wires=1)
qml.Rot(W[2, 0], W[2, 1], W[2, 2], wires=2)
qml.Rot(W[3, 0], W[3, 1], W[3, 2], wires=3)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[1, 2])
qml.CNOT(wires=[2, 3])
qml.CNOT(wires=[3, 0])