# TODO, show differences related to post-selecting for depth vs post-selectng for total gates added
from qiskit.transpiler import CouplingMap
from mirror_gates.pass_managers import Mirage, QiskitLevel3
from transpile_benchy.metrics.gate_counts import DepthMetric, TotalMetric
from mirror_gates.logging import transpile_benchy_logger

from transpile_benchy.library import CircuitLibrary

library = CircuitLibrary.from_txt("../../circuits/medium_circuits.txt")

coupling_map = CouplingMap.from_heavy_hex(5)
transpilers = [
    QiskitLevel3(coupling_map),  # 20,4,20
    Mirage(
        coupling_map,
        name="Mirage-Min-Swaps",
        cost_function="basic",
        fixed_aggression=1,
    ),
    Mirage(
        coupling_map,
        name="Mirage-Min-Depth",
        fixed_aggression=1,
    ),
]

metrics = [DepthMetric(consolidate=False), TotalMetric(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=5,
    logger=transpile_benchy_logger,
)
benchmark.run()

benchmark.summary_statistics(transpilers[0], transpilers[1])

benchmark.summary_statistics(transpilers[1], transpilers[2])

benchmark.summary_statistics(transpilers[0], transpilers[2])

from transpile_benchy.render import plot_benchmark

plot_benchmark(
    benchmark,
    save=1,
    legend_show=1,
    filename="post",
    override_legend=["Qiskit", "MIRAGE-Swaps", "MIRAGE-Depth"],
)

print(benchmark)