Skip to content

Commit

Permalink
Merge pull request #8 from qc-tum/deduplicate
Browse files Browse the repository at this point in the history
Deduplicate code base
  • Loading branch information
Gistbatch authored Jan 25, 2024
2 parents 56e5955 + f15e982 commit 703bdb3
Show file tree
Hide file tree
Showing 34 changed files with 1,983 additions and 1,587 deletions.
632 changes: 632 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions data/benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
"""Benchmarking tools for the MILP model."""
from .generate_baseline_schedules import generate_baseline_schedule
from .generate_milp_schedules import (
calculate_makespan,
generate_extended_schedule,
generate_simple_schedule,
set_up_base_lp,
)
from .benchmark import run_experiments
from .processing import analyze_benchmarks
55 changes: 28 additions & 27 deletions data/benchmark/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
"""Generates the benchmark data."""
from copy import deepcopy

from mqt.bench import get_benchmark
from qiskit import QuantumCircuit
import numpy as np

from utils.helpers import Timer

from .generate_baseline_schedules import generate_baseline_schedule
from .generate_milp_schedules import (
generate_extended_schedule,
generate_simple_schedule,
set_up_base_lp,
from src.scheduling import (
Benchmark,
InfoProblem,
PTimes,
Result,
SchedulerType,
STimes,
generate_schedule,
)
from .types import Benchmark, PTimes, Result, STimes
from utils.helpers import Timer


def _generate_batch(max_qubits: int, circuits_per_batch: int) -> list[QuantumCircuit]:
Expand Down Expand Up @@ -64,35 +63,37 @@ def run_experiments(
]
benchmark_results: list[dict[str, PTimes | STimes | dict[str, Result]]] = []
for benchmark in benchmarks:
lp_instance = set_up_base_lp(
benchmark, setting, big_m=1000, timesteps=list(range(t_max))
)
p_times = _get_processing_times(benchmark, setting, get_integers)
s_times = _get_setup_times(
# lp_instance = set_up_base_lp(
# benchmark, setting, big_m=1000, timesteps=list(range(t_max))
# )
p_times = _get_benchmark_processing_times(benchmark, setting, get_integers)
s_times = _get_benchmark_setup_times(
benchmark, setting, default_value=2**5, get_integers=get_integers
)
problem = InfoProblem(
base_jobs=benchmark,
accelerators=setting,
big_m=1000,
timesteps=t_max,
process_times=p_times,
setup_times=s_times,
)
result: dict[str, Result] = {}

# Run the baseline model
with Timer() as t0:
makespan, jobs = generate_baseline_schedule(
benchmark, setting, p_times, s_times
)
makespan, jobs, _ = generate_schedule(problem, SchedulerType.BASELINE)
result["baseline"] = Result(makespan, jobs, t0.elapsed)

# Run the simple model
lp_instance_copy = deepcopy(lp_instance)

with Timer() as t1:
makespan, jobs = generate_simple_schedule(
lp_instance_copy, p_times, s_times
)
makespan, jobs, _ = generate_schedule(problem, SchedulerType.SIMPLE)
result["simple"] = Result(makespan, jobs, t1.elapsed)

# Run the extended model
with Timer() as t2:
makespan, jobs = generate_extended_schedule(
lp_instance, p_times, s_times
)
makespan, jobs, _ = generate_schedule(problem, SchedulerType.EXTENDED)
result["extended"] = Result(makespan, jobs, t2.elapsed)

# Store results
Expand All @@ -104,7 +105,7 @@ def run_experiments(
return results


def _get_processing_times(
def _get_benchmark_processing_times(
base_jobs: list[QuantumCircuit],
accelerators: dict[str, int],
get_integers: bool = False,
Expand All @@ -117,7 +118,7 @@ def _get_processing_times(
]


def _get_setup_times(
def _get_benchmark_setup_times(
base_jobs: list[QuantumCircuit],
accelerators: dict[str, int],
default_value: float,
Expand Down
164 changes: 0 additions & 164 deletions data/benchmark/generate_baseline_schedules.py

This file was deleted.

13 changes: 7 additions & 6 deletions data/benchmark/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ def analyze_benchmarks(in_file: str) -> dict[str, ImprovementResult]:
# Loop through each benchmark
for benchmark in benchmarks:
# Extract the makespan values
results = benchmark["results"]
makespans.append(
MakespanResult(
baseline=benchmark["baseline"]["makespan"],
simple=benchmark["simple"]["makespan"],
extended=benchmark["extended"]["makespan"],
baseline=results["baseline"]["makespan"],
simple=results["simple"]["makespan"],
extended=results["extended"]["makespan"],
)
)
times.append(
TimingResult(
baseline=benchmark["baseline"]["time"],
simple=benchmark["simple"]["time"],
extended=benchmark["extended"]["time"],
baseline=results["baseline"]["time"],
simple=results["simple"]["time"],
extended=results["extended"]["time"],
)
)

Expand Down
65 changes: 0 additions & 65 deletions data/benchmark/types.py

This file was deleted.

2 changes: 2 additions & 0 deletions data/example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Example MILP problem."""
from .example_problem import example_problem
Loading

0 comments on commit 703bdb3

Please sign in to comment.