from mirror_gates.sycamore import syc
from transpile_benchy.utilities.numerical_decomp import (
    Advanced2QDecomposer,
    BasicDecomposer,
)
from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
from qiskit.circuit.parameter import Parameter
from qiskit.circuit.library import CXGate, SwapGate, CZGate, iSwapGate

decomposer = BasicDecomposer(basis_gates=[(syc, 2)])

from qiskit.transpiler.passes import Optimize1qGates
from qiskit.transpiler import PassManager

ansatz = QuantumCircuit(2)
ansatz.u(Parameter("p000"), Parameter("p001"), Parameter("p002"), 0)
ansatz.u(Parameter("q000"), Parameter("q001"), Parameter("q002"), 1)
ansatz.append(iSwapGate().power(-1), [0, 1])
ansatz.append(CZGate().power(1 / 6), [0, 1])
ansatz.u(Parameter("p003"), Parameter("p004"), Parameter("p005"), 0)
ansatz.u(Parameter("q003"), Parameter("q004"), Parameter("q005"), 1)
ansatz.append(iSwapGate().power(-1), [0, 1])
ansatz.append(CZGate().power(1 / 6), [0, 1])
ansatz.u(Parameter("p006"), Parameter("p007"), Parameter("p008"), 0)
ansatz.u(Parameter("q006"), Parameter("q007"), Parameter("q008"), 1)
ret = decomposer.decompose_from_ansatz(target=CXGate(), ansatz=ansatz)
pm = PassManager()
pm.append(Optimize1qGates())
ret = pm.run(ret)
ret.draw("mpl")

ret.qasm(filename="d02_syc_cnot.qasm")

ansatz = QuantumCircuit(2)
ansatz.u(Parameter("p000"), Parameter("p001"), Parameter("p002"), 0)
ansatz.u(Parameter("q000"), Parameter("q001"), Parameter("q002"), 1)
ansatz.append(iSwapGate().power(-1), [0, 1])
ansatz.append(CZGate().power(1 / 6), [0, 1])
ansatz.u(Parameter("p003"), Parameter("p004"), Parameter("p005"), 0)
ansatz.u(Parameter("q003"), Parameter("q004"), Parameter("q005"), 1)
ansatz.append(iSwapGate().power(-1), [0, 1])
ansatz.append(CZGate().power(1 / 6), [0, 1])
ansatz.u(Parameter("p006"), Parameter("p007"), Parameter("p008"), 0)
ansatz.u(Parameter("q006"), Parameter("q007"), Parameter("q008"), 1)
ansatz.append(iSwapGate().power(-1), [0, 1])
ansatz.append(CZGate().power(1 / 6), [0, 1])
ansatz.u(Parameter("p009"), Parameter("p010"), Parameter("p011"), 0)
ansatz.u(Parameter("q009"), Parameter("q010"), Parameter("q011"), 1)
ret = decomposer.decompose_from_ansatz(target=SwapGate(), ansatz=ansatz)
pm.append(Optimize1qGates())
ret = pm.run(ret)
ret.draw("mpl")

ret.qasm(filename="d02_syc_swap.qasm")