forked from anastasiaangelo/ProjectAnastasia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawcircuit_4q.py
46 lines (38 loc) · 1.16 KB
/
drawcircuit_4q.py
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
46
from qiskit import QuantumCircuit
import matplotlib.pyplot as plt
# Initialize the quantum circuit for 4 qubits
qc = QuantumCircuit(4)
# Define the coefficients from the Hamiltonian
coefficients = {
'ZZII': 6.0,
'ZIZI': 0.1809819192,
'ZIIZ': 0.1892471462,
'IZZI': 0.0227315873,
'IZIZ': 0.0304955691,
'IIZZ': 6.0,
'ZIII': -0.7314345837,
'IZII': -0.5840745270,
'IIZI': -0.9879427254,
'IIIZ': -0.9066044092
}
# Function to add a ZZ operation between two qubits
def add_zz(qc, coeff, q1, q2):
angle = 2 * coeff # The angle for RZ is twice the coefficient for ZZ
qc.cx(q1, q2)
qc.rz(angle, q2)
qc.cx(q1, q2)
# Apply the ZZ terms
add_zz(qc, coefficients['ZZII'], 0, 1)
add_zz(qc, coefficients['ZIZI'], 0, 2)
add_zz(qc, coefficients['ZIIZ'], 0, 3)
add_zz(qc, coefficients['IZZI'], 1, 2)
add_zz(qc, coefficients['IZIZ'], 1, 3)
add_zz(qc, coefficients['IIZZ'], 2, 3)
# Apply single Z rotations
qc.rz(2 * -0.7314345837, 0) # 2 * coefficient for the RZ rotation
qc.rz(2 * -0.5840745270, 1)
qc.rz(2 * -0.9879427254, 2)
qc.rz(2 * -0.9066044092, 3)
# Visualize the circuit
figure = qc.draw('mpl')
figure.savefig("quantum_circuit.pdf")