from qiskit.transpiler import CouplingMap
from mirror_gates.pass_managers import Mirage, QiskitLevel3
from mirror_gates.logging import transpile_benchy_logger

from transpile_benchy.library import CircuitLibrary

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

coupling_map = CouplingMap.from_line(64)
# coupling_map = CouplingMap.from_heavy_hex(5)

# XXX we hardcoded layout to not be parallelized to avoid a pipe error
# before collecting data for this result -> change the hardcoded value

# maybe requires downgrading to 3.9 to get this to work....????

transpilers = [
    QiskitLevel3(coupling_map, python_sabre=True),
    Mirage(
        coupling_map,
        use_fast_settings=True,
        name="Mirage",
        parallel=True,
        swap_trials=6,
        layout_trials=6,
    ),
]

from transpile_benchy.benchmark import Benchmark

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

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

from transpile_benchy.render import plot_benchmark

plot_benchmark(
    benchmark,
    save=1,
    legend_show=1,
    filename="speed",
    plot_type="trendline",
    color_override=[0, 3],
)

print(benchmark)