Bases: object
Equivalently transfrom circuit into goal instruction set
Examples:
>>> from QuICT.core.virtual_machine.special_set import USTCSet
>>> from QuICT.qcda.synthesis.gate_transform import GateTransform
>>> gt = GateTransform(USTCSet)
>>> circ_syn = gt.execute(circ)
Parameters:
-
instruction_set
(InstructionSet, default:
USTCSet
)
–
-
keep_phase
(bool, default:
False
)
–
whether to keep the global phase as a GPhase gate in the output
Source code in QuICT/qcda/synthesis/gate_transform/gate_transform.py
| def __init__(self, instruction_set=USTCSet, keep_phase=False):
"""
Args:
instruction_set (InstructionSet): the goal instruction set
keep_phase (bool, optional): whether to keep the global phase as a GPhase gate in the output
"""
self.instruction_set = instruction_set
self.keep_phase = keep_phase
self.total_phase = 0
|
execute(circuit: Union[Circuit, CompositeGate]) -> CompositeGate
Transform the two-qubit gate into instruction set one by one, then one-qubit gate
Parameters:
Returns:
-
CompositeGate ( CompositeGate
) –
the equivalent compositeGate with goal instruction set
Source code in QuICT/qcda/synthesis/gate_transform/gate_transform.py
| @OutputAligner()
def execute(self, circuit: Union[Circuit, CompositeGate]) -> CompositeGate:
"""
Transform the two-qubit gate into instruction set one by one, then one-qubit gate
Args:
circuit (Circuit/CompositeGate): the circuit to be transformed
Returns:
CompositeGate: the equivalent compositeGate with goal instruction set
"""
assert isinstance(circuit, (Circuit, CompositeGate)), TypeError("Invalid input for GateTransform")
gates = circuit if isinstance(circuit, CompositeGate) else circuit.to_compositegate()
gates.decomposition()
gates.flatten()
gates = self.two_qubit_transform(gates)
gates = self.one_qubit_transform(gates)
self._clean_identity_matrix(gates)
if self.keep_phase:
self.total_phase = np.mod(self.total_phase, 2 * np.pi)
if not np.isclose(self.total_phase, 0) and not np.isclose(self.total_phase, 2 * np.pi):
gates.append(GPhase(self.total_phase) & 0)
return gates
|