-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage-samples.py
More file actions
executable file
·45 lines (36 loc) · 1.32 KB
/
image-samples.py
File metadata and controls
executable file
·45 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
import pennylane as qml
import matplotlib.pyplot as plt
import matplotlib
QUBITS = 3
def create_pennylane_circuit(instructions: list[list[int]]):
dev = qml.device("default.qubit", wires=QUBITS)
@qml.qnode(dev)
def circuit(xparams=[], yparams=[]):
for q in range(QUBITS):
qml.Hadamard(wires=q)
qml.RZ(xparams[q], wires=q)
idx = 0
for layer in instructions:
for qbit, op in enumerate(layer):
if op == 0:
continue
elif op == 1:
qml.Hadamard(wires=qbit)
elif op == 2:
qml.RZ(yparams[idx] * xparams[qbit], wires=qbit)
idx += 1
elif op == 3:
qml.RX(yparams[idx] * xparams[qbit], wires=qbit)
idx += 1
elif op == 4:
qml.RY(yparams[idx] * xparams[qbit], wires=qbit)
idx += 1
elif op == 5:
qml.CNOT(wires=[qbit, (qbit - 1) % QUBITS])
return qml.state()
return circuit
matplotlib.use("tkagg")
circ = create_pennylane_circuit([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]])
fig, ax = qml.draw_mpl(circ)([1, 2, 3], [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3])
plt.show()