# imports

from qiskit.circuit import QuantumCircuit

from qiskit.circuit.library import PermutationGate

from qiskit.transpiler.passes.synthesis.high_level_synthesis import (
    HighLevelSynthesis,
    HighLevelSynthesisPluginManager,
    HighLevelSynthesisPlugin,
    HLSConfig,
)

from qiskit.compiler import transpile

from qiskit.transpiler import CouplingMap

qc = QuantumCircuit(6)

perm = PermutationGate([1, 2, 3, 4, 0])
qc.append(perm, [1, 2, 3, 4, 5])

qc.draw(output='mpl')

qct = transpile(qc)
qct.draw(output='mpl')

qct = HighLevelSynthesis()(qc)
qct.draw(output='mpl')

print(HighLevelSynthesisPluginManager().method_names("permutation"))

config = HLSConfig(permutation=["acg"])
qct = HighLevelSynthesis(hls_config=config)(qc)
qct.draw(output='mpl')

config = HLSConfig(permutation=["kms"])
qct = HighLevelSynthesis(hls_config=config)(qc)
qct.draw(output='mpl')

config = HLSConfig(permutation=["kms"])
qct = transpile(qc, hls_config=config)
qct.draw(output='mpl')

config = HLSConfig(permutation=["token_swapper"])
qct = HighLevelSynthesis(hls_config=config)(qc)
qct.draw(output='mpl')

config = HLSConfig(permutation=["token_swapper"])
coupling_map = CouplingMap([[1, 2], [1, 3], [1, 4], [1, 5]])
qct = HighLevelSynthesis(hls_config=config, coupling_map=coupling_map, use_qubit_indices=True)(qc)
qct.draw(output='mpl')

config = HLSConfig(permutation=["token_swapper"])
coupling_map = CouplingMap([[1, 2], [2, 3], [2, 4], [2, 5]])
qct = HighLevelSynthesis(hls_config=config, coupling_map=coupling_map, use_qubit_indices=True)(qc)
qct.draw(output='mpl')

config = HLSConfig(permutation=["token_swapper"])
coupling_map = CouplingMap.from_ring(6)
qct = HighLevelSynthesis(hls_config=config, coupling_map=coupling_map, use_qubit_indices=True)(qc)
qct.draw(output='mpl')


coupling_map = CouplingMap([[0, 1], [1, 2], [3, 4], [4, 5]])
config = HLSConfig(permutation=["token_swapper"])

qc = QuantumCircuit(6)
qc.append(PermutationGate([1, 0, 3, 2]), [1, 2, 3, 4])
config = HLSConfig(permutation=[("token_swapper", {"trials": 10})])
qct = HighLevelSynthesis(hls_config=config, coupling_map=coupling_map, use_qubit_indices=True)(qc)
qct.draw(output='mpl')

coupling_map = CouplingMap([[0, 1], [1, 2], [3, 4], [4, 5]])
config = HLSConfig(permutation=["token_swapper"])

qc = QuantumCircuit(6)
qc.append(PermutationGate([1, 0, 3, 2]), [1, 4, 2, 3])
config = HLSConfig(permutation=[("token_swapper", {"trials": 10})])
qct = HighLevelSynthesis(hls_config=config, coupling_map=coupling_map, use_qubit_indices=True)(qc)
qct.draw(output='mpl')