|
8 | 8 | import json |
9 | 9 | from itertools import product |
10 | 10 | import random |
| 11 | +import gc |
11 | 12 |
|
12 | 13 | from qiskit import QuantumCircuit, ClassicalRegister |
13 | 14 | from qiskit.transpiler import generate_preset_pass_manager, StagedPassManager |
|
33 | 34 | States = List[int] |
34 | 35 | Measurements = List[int] |
35 | 36 |
|
36 | | - |
37 | 37 | class CircuitResult(TypedDict): |
38 | 38 | """Type for circuit results""" |
39 | 39 |
|
@@ -139,7 +139,6 @@ def generate_images( |
139 | 139 | """ |
140 | 140 |
|
141 | 141 | dataset_file_path = dataset_file(target_folder) |
142 | | - df = open_csv(dataset_file_path) |
143 | 142 |
|
144 | 143 | bitstrings_to_int = [ |
145 | 144 | int("".join(comb), 2) for comb in product("01", repeat=n_qubits) |
@@ -170,12 +169,20 @@ def generate_images( |
170 | 169 |
|
171 | 170 | with ThreadPoolExecutor(max_workers=total_threads) as pool: |
172 | 171 | threads = [pool.submit(generate_image, *arg) for arg in args] # type:ignore |
| 172 | + df = open_csv(dataset_file_path) |
| 173 | + |
173 | 174 | for future in as_completed(threads): # type: ignore |
174 | 175 | tmp_df = create_df(future.result()) |
175 | 176 | df.vstack(tmp_df, in_place=True) |
176 | 177 |
|
| 178 | + save_df(df, dataset_file_path) |
| 179 | + |
| 180 | + # remove df from memory to open avoid excess |
| 181 | + # of memory usage |
| 182 | + del df |
| 183 | + gc.collect() |
| 184 | + |
177 | 185 | progress.update(total_threads) |
178 | | - save_df(df, dataset_file_path) |
179 | 186 |
|
180 | 187 |
|
181 | 188 | def remove_duplicated_files(target_folder: FilePath): |
|
0 commit comments