Skip to content

Commit e4f40da

Browse files
committed
remove df from memory after each iteration
1 parent bd4ab80 commit e4f40da

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

generate/dataset.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
from itertools import product
1010
import random
11+
import gc
1112

1213
from qiskit import QuantumCircuit, ClassicalRegister
1314
from qiskit.transpiler import generate_preset_pass_manager, StagedPassManager
@@ -33,7 +34,6 @@
3334
States = List[int]
3435
Measurements = List[int]
3536

36-
3737
class CircuitResult(TypedDict):
3838
"""Type for circuit results"""
3939

@@ -139,7 +139,6 @@ def generate_images(
139139
"""
140140

141141
dataset_file_path = dataset_file(target_folder)
142-
df = open_csv(dataset_file_path)
143142

144143
bitstrings_to_int = [
145144
int("".join(comb), 2) for comb in product("01", repeat=n_qubits)
@@ -170,12 +169,20 @@ def generate_images(
170169

171170
with ThreadPoolExecutor(max_workers=total_threads) as pool:
172171
threads = [pool.submit(generate_image, *arg) for arg in args] # type:ignore
172+
df = open_csv(dataset_file_path)
173+
173174
for future in as_completed(threads): # type: ignore
174175
tmp_df = create_df(future.result())
175176
df.vstack(tmp_df, in_place=True)
176177

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+
177185
progress.update(total_threads)
178-
save_df(df, dataset_file_path)
179186

180187

181188
def remove_duplicated_files(target_folder: FilePath):

0 commit comments

Comments
 (0)