# TODO, show how different aggression configurations impact results
from qiskit.transpiler import CouplingMap
from mirror_gates.pass_managers import Mirage, QiskitLevel3
from transpile_benchy.metrics.abc_metrics import MetricInterface
from transpile_benchy.metrics.gate_counts import DepthMetric
from mirror_gates.utilities import DoNothing
from mirror_gates.logging import transpile_benchy_logger

from transpile_benchy.library import CircuitLibrary

library = CircuitLibrary.from_txt("../../circuits/select.txt")
coupling_map = CouplingMap.from_heavy_hex(5)

total_work = 80
transpilers = [
    QiskitLevel3(coupling_map),
    Mirage(coupling_map, name="Mirage"),
    # Mirage(
    #     coupling_map,
    #     name="Mirage-b2",
    #     layout_trials=3,
    #     fb_iters=total_work // 3,
    #     anneal_routing=True,
    # ),
    Mirage(
        coupling_map,
        name="Mirage-b3",
        layout_trials=4,
        fb_iters=total_work // 4,
        anneal_routing=True,
    ),
]

metrics = [DepthMetric(consolidate=False)]

from transpile_benchy.benchmark import Benchmark

# only interested in TimeMetric, is there by default
benchmark = Benchmark(
    transpilers=transpilers,
    circuit_library=library,
    metrics=metrics,
    num_runs=1,
    logger=transpile_benchy_logger,
)
benchmark.run()

print(benchmark.summary_statistics(transpilers[0], transpilers[1])["monodromy_depth"])
print(benchmark.summary_statistics(transpilers[0], transpilers[2])["monodromy_depth"])
# print(benchmark.summary_statistics(transpilers[0], transpilers[3])["monodromy_depth"])

from transpile_benchy.render import plot_benchmark

plot_benchmark(benchmark, save=0, legend_show=1, filename="annealing")