-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine.py
40 lines (32 loc) · 1.32 KB
/
combine.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
import csv
from collections import defaultdict
def load_counts(filename):
counts = {}
with open(filename, 'r') as csvfile:
csvreader = csv.reader(csvfile)
next(csvreader) # Skip header
for row in csvreader:
state, count = row
counts[state] = int(count)
return counts
def combine_counts(counts1, counts2):
combined_counts = defaultdict(int)
for state1, count1 in counts1.items():
for state2, count2 in counts2.items():
combined_state = state1 + state2 # Combine states
combined_counts[combined_state] += count1 + count2
return combined_counts
def save_combined_counts(filename, combined_counts):
with open(filename, 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(['State', 'Counts'])
for state, count in combined_counts.items():
csvwriter.writerow([state, count])
# Load counts from the individual 30-qubit simulations
counts1 = load_counts('simulation_results_3.csv')
counts2 = load_counts('simulation_results_4.csv')
# Combine counts
combined_counts = combine_counts(counts1, counts2)
# Save combined results
save_combined_counts('combined_simulation_results2.csv', combined_counts)
print("Combined simulation results saved to 'combined_simulation_results2.csv'.")