# 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 transpile_benchy.library import CircuitLibrary

library = CircuitLibrary.from_txt("../../circuits/aggression_select.txt")
# library = CircuitLibrary.from_txt("../../circuits/small_circuits.txt")
# library = CircuitLibrary.from_txt("speedups.txt")

coupling_map = CouplingMap.from_heavy_hex(5)
transpilers = [
    QiskitLevel3(coupling_map),
    Mirage(coupling_map, name="Mirage-a0", fixed_aggression=0, no_vf2=True),
    Mirage(coupling_map, name="Mirage-a1", fixed_aggression=1, no_vf2=True),
    Mirage(coupling_map, name="Mirage-a2", fixed_aggression=2, no_vf2=True),
    Mirage(coupling_map, name="Mirage-a3", fixed_aggression=3, no_vf2=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,
)
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"])
print(benchmark.summary_statistics(transpilers[0], transpilers[4])["monodromy_depth"])

from transpile_benchy.render import plot_benchmark

plot_benchmark(
    benchmark,
    save=0,
    legend_show=1,
    filename="aggression",
    color_override=[0, 2, 4, 5, 6],
    auto_sort=0,
    override_legend=[
        "Qiskit",
        "Mirage-a0",
        "Mirage-a1",
        "Mirage-a2",
        "Mirage-a3",
    ],
)