Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
Attempt to refactor runner.py again
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterkemeny committed Feb 12, 2024
1 parent 534203b commit d8738d9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions red_queen/runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
This module contains the Runner class, which is responsible for running benchmarks on a given backend using a given compiler.
This module contains the Runner class, which is responsible for
running benchmarks on a given backend using a given compiler.
"""

# This code is licensed under the Apache License, Version 2.0. You may
Expand Down Expand Up @@ -68,6 +69,8 @@
import qiskit
from qiskit import transpile, QuantumCircuit
from qiskit import qasm2

# pylint: disable=import-error
from memory_profiler import memory_usage
import numpy as np

Expand All @@ -82,10 +85,12 @@

logger.addHandler(console_handler)

# TODO: comment this class well


class Runner:
"""
Class for running benchmarks on a given backend using a given compiler.
"""

def __init__(
self,
compiler_dict: dict,
Expand Down Expand Up @@ -218,6 +223,12 @@ def save_results(self):
json.dump([self.metric_data], json_file)

def transpile_in_process(self, benchmark, optimization_level):
"""
Transpile a circuit in a separate process to get memory usage.
:param benchmark: benchmark to be transpiled
:param optimization_level: level of optimization to be used
"""
backend = choose_backend(self.backend) # FakeFlamingo(11) #
start_mem = memory_usage(max_usage=True)
if self.compiler_dict["compiler"] == "pytket":
Expand All @@ -233,6 +244,11 @@ def transpile_in_process(self, benchmark, optimization_level):
return memory

def profile_func(self, benchmark):
"""
Profile a function to get memory usage.
:param benchmark: benchmark to be run
"""
# To get accurate memory usage, need to multiprocess transpilation
with multiprocessing.Pool(1) as pool:
memory = pool.apply(
Expand Down

0 comments on commit d8738d9

Please sign in to comment.