-
Notifications
You must be signed in to change notification settings - Fork 0
/
sixty-part9.py
60 lines (46 loc) · 1.66 KB
/
sixty-part9.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
47
48
49
50
51
52
53
54
55
56
57
58
59
from qiskit import QuantumCircuit, Aer, transpile, assemble
from qiskit_aer import Aer
import csv
def generate_60_qubit_circuit():
num_qubits = 60
num_layers = 5 # Number of layers in the brickwork pattern
qc = QuantumCircuit(num_qubits)
for layer in range(num_layers):
# Apply single-qubit gates (example: Hadamard gates)
qc.h(range(num_qubits))
# Apply two-qubit gates in a brickwork pattern
if layer % 2 == 0:
for i in range(0, num_qubits - 1, 2):
qc.cx(i, i + 1)
else:
for i in range(1, num_qubits - 1, 2):
qc.cx(i, i + 1)
qc.measure_all()
return qc
def run_simulation(qc, shots=1024):
# Use the AerSimulator for local simulation
simulator = Aer.get_backend('aer_simulator')
# Transpile the circuit for the simulator
compiled_circuit = transpile(qc, simulator)
# Assemble the circuit
qobj = assemble(compiled_circuit, shots=shots)
# Run the simulation
result = simulator.run(qobj).result()
# Get measurement counts
counts = result.get_counts()
return counts
def write_counts_to_csv(counts, filename):
with open(filename, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Result', 'Count'])
for key, value in counts.items():
writer.writerow([key, value])
# Main execution
if __name__ == "__main__":
# Generate the circuit
qc = generate_60_qubit_circuit()
# Run the simulation
counts = run_simulation(qc)
# Write results to CSV
csv_filename = 'results.csv'
write_counts_to_csv(counts, csv_filename)