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(**inp):
# Split inputs again
ks = [int(k) for k in inp.keys()]
vs = inp.values()
inp = [x for _, x in sorted(zip(ks, vs))]
inp1 = inp[:n]
inp2 = inp[n:]
# Circuit
templ1(*inp1, **hyperparameters1)
templ2(*inp2, **hyperparameters2)
qml.PauliX(wires=1)
return [qml.expval(qml.Identity(0)), qml.expval(qml.PauliX(1))]
def circuit(x):
qml.PauliX(wires=0)
qml.CRY(x, wires=[0, 1])
return qml.expval(qml.PauliZ(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))
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):
qml.RZ(x, wires=[1]).inv()
qml.RZ(x, wires=[1]).inv().inv()
return qml.expval(qml.PauliX(0)), qml.expval(qml.PauliZ(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 test_state_non_analytic(self, simulator_device_2_wires):
"""Test that the state is None if in non-analytic mode."""
simulator_device_2_wires.reset()
simulator_device_2_wires.apply([qml.PauliX(0), qml.PauliX(1)])
assert simulator_device_2_wires.state is None
def test_paulix_expectation(self, shots, qvm, compiler):
"""Test that PauliX expectation value is correct"""
theta = 0.432
phi = 0.123
dev = plf.QVMDevice(device="2q-qvm", shots=shots)
dev.apply("RY", wires=[0], par=[theta])
dev.apply("RY", wires=[1], par=[phi])
dev.apply("CNOT", wires=[0, 1], par=[])
O = qml.PauliX
name = "PauliX"
dev._obs_queue = [O(wires=[0], do_queue=False), O(wires=[1], do_queue=False)]
dev.pre_measure()
res = np.array([dev.expval(name, [0], []), dev.expval(name, [1], [])])
# below are the analytic expectation values for this circuit
self.assertAllAlmostEqual(
res, np.array([np.sin(theta) * np.sin(phi), np.sin(phi)]), delta=3 / np.sqrt(shots)
)
def test_eigvals(self):
"""Test that the correct eigenvalues are returned for the Tensor"""
X = qml.PauliX(0)
Y = qml.PauliY(2)
t = Tensor(X, Y)
assert np.array_equal(t.eigvals, np.kron(qml.PauliX.eigvals, qml.PauliY.eigvals))
def test_obs_queue_is_filled_during_execution(self, monkeypatch, mock_device_with_paulis_and_methods):
"""Tests that the operations are properly applied and queued"""
observables = [
qml.expval(qml.PauliX(0)),
qml.var(qml.PauliY(1)),
qml.sample(qml.PauliZ(2)),
]
# capture the arguments passed to dev methods
expval_args = []
var_args = []
sample_args = []
with monkeypatch.context() as m:
m.setattr(Device, 'expval', lambda self, *args: expval_args.extend(args))
m.setattr(Device, 'var', lambda self, *args: var_args.extend(args))
m.setattr(Device, 'sample', lambda self, *args: sample_args.extend(args))
mock_device_with_paulis_and_methods.execute([], observables)
assert expval_args == ["PauliX", [0], []]
assert var_args == ["PauliY", [1], []]