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)
qml.CNOT(wires=[1, 2])
qml.RX(c, wires=2)
qml.CNOT(wires=[0, 1])
qml.RZ(c, wires=2)
return qml.var(qml.PauliZ(0)), qml.expval(qml.PauliZ(1)), qml.var(qml.PauliZ(2))
def template(x):
for i in range(5):
qml.RZ(i * x, wires=0)
return qml.var(qml.PauliZ(0)), qml.sample(qml.PauliX(1))
rz = lambda theta: np.cos(theta / 2) * I + 1j * np.sin(-theta / 2) * Z
rot = lambda a, b, c: rz(c) @ (ry(b) @ rz(a))
crz = lambda theta: np.array(
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, np.exp(-1j * theta / 2), 0],
[0, 0, 0, np.exp(1j * theta / 2)],
]
)
single_qubit = [(qml.PauliX, X), (qml.PauliY, Y), (qml.PauliZ, Z), (qml.Hadamard, H)]
single_qubit_param = [(qml.PhaseShift, phase_shift), (qml.RX, rx), (qml.RY, ry), (qml.RZ, rz)]
two_qubit = [(qml.CNOT, CNOT), (qml.SWAP, SWAP)]
two_qubit_param = [(qml.CRZ, crz)]
three_qubit = [(qml.Toffoli, Toffoli), (qml.CSWAP, CSWAP)]
#####################################################
# Fixtures
#####################################################
@pytest.fixture
def init_state(scope="session"):
"""Generates a random initial state"""
def _init_state(n):
"""random initial state"""
def layer3_off_diag_first_order(x, y, z, h, g, f):
non_parametrized_layer(a, b, c)
qml.RX(x, wires=0)
qml.RY(y, wires=1)
qml.RZ(z, wires=2)
non_parametrized_layer(a, b, c)
return qml.expval(qml.PauliZ(2)), qml.expval(qml.PauliY(1))
def non_parametrized_layer(a, b, c):
qml.RX(a, wires=0)
qml.RX(b, wires=1)
qml.RX(c, wires=1)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[1, 2])
qml.RZ(a, wires=0)
qml.Hadamard(wires=1)
qml.CNOT(wires=[0, 1])
qml.RZ(b, wires=1)
qml.Hadamard(wires=0)
def non_parametrized_layer(a, b, c):
qml.RX(a, wires=0)
qml.RX(b, wires=1)
qml.RX(c, wires=1)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[1, 2])
qml.RZ(a, wires=0)
qml.Hadamard(wires=1)
qml.CNOT(wires=[0, 1])
qml.RZ(b, wires=1)
qml.Hadamard(wires=0)
def circuit(phi, theta):
qml.RX(theta, wires=0)
qml.RZ(phi, wires=0)
return qml.expval(qml.PauliZ(0))
def encoding(phi, gamma):
for i in range(3):
qml.RZ(phi[i], wires=[i])
cirq_ops.PhaseDamp(gamma, wires=[i])
def generator(w):
"""Circuit that serves as a generator.
Args:
w (array[float]): variables of the circuit
"""
qml.RX(w[0], wires=0)
qml.RX(w[1], wires=1)
qml.RY(w[2], wires=0)
qml.RY(w[3], wires=1)
qml.RZ(w[4], wires=0)
qml.RZ(w[5], wires=1)
qml.CNOT(wires=[0,1])
qml.RX(w[6], wires=0)
qml.RY(w[7], wires=0)
qml.RZ(w[8], wires=0)
def discriminator(w):
"""Circuit that serves as a discriminator. Same structure as generator.
Args:
w (array[float]): variables of the circuit
"""
qml.RX(w[0], wires=0)
qml.RX(w[1], wires=2)
qml.RY(w[2], wires=0)
qml.RY(w[3], wires=2)
qml.RZ(w[4], wires=0)
qml.RZ(w[5], wires=2)
qml.CNOT(wires=[1,2])
qml.RX(w[6], wires=2)
qml.RY(w[7], wires=2)
qml.RZ(w[8], wires=2)