from qiskit.circuit.library import EfficientSU2
from qiskit_transpiler_service.transpiler_service import TranspilerService

circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

cloud_transpiler_service = TranspilerService(
    backend_name="ibm_sherbrooke",
    ai="false",
    optimization_level=3,
)
transpiled_circuit_no_ai = cloud_transpiler_service.run(circuit)

from qiskit.circuit.library import EfficientSU2
from qiskit_transpiler_service.transpiler_service import TranspilerService

circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

cloud_transpiler_service = TranspilerService(
    backend_name="ibm_sherbrooke",
    ai="true",
    optimization_level=1,
)
transpiled_circuit_ai = cloud_transpiler_service.run(circuit)

from qiskit.circuit.library import EfficientSU2
from qiskit_transpiler_service.transpiler_service import TranspilerService

circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

cloud_transpiler_service = TranspilerService(
    backend_name="ibm_sherbrooke",
    ai="auto",
    optimization_level=1,
)
transpiled_circuit_ai_auto = cloud_transpiler_service.run(circuit)

from qiskit.circuit.library import EfficientSU2
from qiskit_transpiler_service.transpiler_service import TranspilerService

circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

cloud_transpiler_service = TranspilerService(
    backend_name="ibm_sherbrooke",
    ai="auto",
    optimization_level=1,
)
transpiled_circuit = cloud_transpiler_service.run(circuit)

from qiskit.transpiler import PassManager
from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit.circuit.library import EfficientSU2

ai_passmanager = PassManager(
    [
        AIRouting(
            backend_name="ibm_sherbrooke", optimization_level=2, layout_mode="optimize"
        )
    ]
)

circuit = EfficientSU2(101, entanglement="circular", reps=1).decompose()

transpiled_circuit_ai_lvl2 = ai_passmanager.run(circuit)

from qiskit.transpiler import PassManager

from qiskit_transpiler_service.ai.routing import AIRouting
from qiskit_transpiler_service.ai.synthesis import AILinearFunctionSynthesis
from qiskit_transpiler_service.ai.collection import CollectLinearFunctions
from qiskit.circuit.library import EfficientSU2

ai_passmanager = PassManager(
    [
        AIRouting(
            backend_name="ibm_torino", optimization_level=3, layout_mode="optimize"
        ),  # Route circuit
        CollectLinearFunctions(),  # Collect Linear Function blocks
        AILinearFunctionSynthesis(
            backend_name="ibm_torino"
        ),  # Re-synthesize Linear Function blocks
    ]
)

circuit = EfficientSU2(10, entanglement="full", reps=1).decompose()

transpiled_circuit_synthesis = ai_passmanager.run(circuit)

print(
    f"Depth: {transpiled_circuit_no_ai.decompose(reps=3).depth()}, Gates(2q): {transpiled_circuit_no_ai.decompose(reps=3).num_nonlocal_gates()}"
)

print(
    f"Depth: {transpiled_circuit_ai.decompose(reps=3).depth()}, Gates(2q): {transpiled_circuit_ai.decompose(reps=3).num_nonlocal_gates()}"
)

print(
    f"Depth: {transpiled_circuit_ai_auto.decompose(reps=3).depth()}, Gates(2q): {transpiled_circuit_ai_auto.decompose(reps=3).num_nonlocal_gates()}"
)

print(
    f"Depth: {transpiled_circuit_ai_lvl2.decompose(reps=3).depth()}, Gates(2q): {transpiled_circuit_ai_lvl2.decompose(reps=3).num_nonlocal_gates()}"
)

print(
    f"Depth: {transpiled_circuit_synthesis.decompose(reps=3).depth()}, Gates(2q): {transpiled_circuit_synthesis.decompose(reps=3).num_nonlocal_gates()}"
)

