Skip to content

Commit

Permalink
Merge pull request #47 from migueldiascosta/reduce_memory_footprint
Browse files Browse the repository at this point in the history
recreate and delete circuit in every run to make sure the GPU memory is freed
  • Loading branch information
scarrazza authored Feb 1, 2024
2 parents d80c5f2 + c78c303 commit 7594351
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions benchmarks/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,32 @@ def circuit_benchmark(nqubits, backend, circuit_name, circuit_options=None,
result = result.numpy()
logs.log(dry_run_transfer_time=time.time() - start_time)
dtype = str(result.state().dtype)
del(result)
del result
del circuit

simulation_times, transfer_times = [], []
creation_times, simulation_times, transfer_times = [], [], []
for _ in range(nreps):
start_time = time.time()
circuit = qibo.models.Circuit(nqubits)
circuit.add(gates)
if nshots is not None:
# add measurement gates
circuit.add(qibo.gates.M(*range(nqubits)))
creation_times.append(time.time() - start_time)
start_time = time.time()
result = circuit(nshots=nshots)
simulation_times.append(time.time() - start_time)
start_time = time.time()
if transfer:
result = result.numpy()
transfer_times.append(time.time() - start_time)
del(result)
del result
del circuit

logs.log(dtype=dtype, simulation_times=simulation_times,
logs.log(dtype=dtype, creation_times=creation_times,
simulation_times=simulation_times,
transfer_times=transfer_times)
logs.average("creation_times")
logs.average("simulation_times")
logs.average("transfer_times")

Expand Down Expand Up @@ -120,14 +131,14 @@ def library_benchmark(nqubits, library, circuit_name, circuit_options=None,
result = backend(circuit)
logs.log(dry_run_time=time.time() - start_time)
dtype = str(result.dtype)
del(result)
del result

simulation_times = []
for _ in range(nreps):
start_time = time.time()
result = backend(circuit)
simulation_times.append(time.time() - start_time)
del(result)
del result

logs.log(dtype=dtype, simulation_times=simulation_times)
logs.average("simulation_times")
Expand Down Expand Up @@ -169,7 +180,7 @@ def evolution_benchmark(nqubits, dt, solver, backend, platform=None,
result = evolution(final_time=1.0)
logs.log(dry_run_time=time.time() - start_time)
dtype = str(result.dtype)
del(result)
del result

simulation_times = []
for _ in range(nreps):
Expand Down

0 comments on commit 7594351

Please sign in to comment.