-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgather_counts.py
More file actions
53 lines (41 loc) · 1.53 KB
/
gather_counts.py
File metadata and controls
53 lines (41 loc) · 1.53 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
46
47
48
49
50
51
52
53
import pickle
from pathlib import Path
from bqskit.ir.circuit import Circuit
def gather_counts(data_dir="out_circuits_pam_3_synth_4"):
"""
Gather two-qudit gate counts for original and compiled circuits.
Args:
data_dir: Directory containing the data objects
Returns:
List of dictionaries with circuit counts
"""
results = []
data_path = Path(data_dir)
input_counts = []
compiled_counts = []
# Iterate through all data files
for file_path in sorted(data_path.glob("*.pkl")):
with open(file_path, 'rb') as f:
data = pickle.load(f)
original_circuit: Circuit = data['input_circuit']
compiled_circuit: Circuit = data['compiled_circuit']
original_counts = count_two_qudit_gates(original_circuit)
compiled_counts = count_two_qudit_gates(compiled_circuit)
input_counts.append(original_counts)
compiled_counts.append(compiled_counts)
all_data = {
"input_counts": input_counts,
"compiled_counts": compiled_counts
}
return all_data
def count_two_qudit_gates(circuit: Circuit):
"""Count two-qudit gates in a circuit."""
two_qudit_gates = 0
for op in circuit.operations():
if len(op.location) >= 2: # Check if it's a two-qudit gate
two_qudit_gates += 1
return two_qudit_gates
if __name__ == "__main__":
all_data = gather_counts()
with open("twoq_gate_count_data_all_to_all.pkl", 'wb') as f:
pickle.dump(all_data, f)