Try replacing a given SingleQubitGate with a default SingleQubitGate.
It does that by matching the input SingleQubitGate to a default SingleQubitGate.
Returns:
| Type |
Description |
SingleQubitGate
|
A default SingleQubitGate if this SingleQubitGate is close to it,
|
SingleQubitGate
|
or the input SingleQubitGate otherwise.
|
Source code in opensquirrel/ir/single_qubit_gate.py
| def try_match_replace_with_default_gate(gate: SingleQubitGate) -> SingleQubitGate:
"""Try replacing a given SingleQubitGate with a default SingleQubitGate.
It does that by matching the input SingleQubitGate to a default SingleQubitGate.
Returns:
A default SingleQubitGate if this SingleQubitGate is close to it,
or the input SingleQubitGate otherwise.
"""
from opensquirrel.default_instructions import (
default_bsr_set_without_rn,
default_bsr_with_angle_param_set,
)
from opensquirrel.ir.default_gates.single_qubit_gates import Rn
for gate_name in default_bsr_set_without_rn:
arguments: tuple[Any, ...] = (gate.qubit,)
if gate_name in default_bsr_with_angle_param_set:
arguments += (Float(gate.bsr.angle),)
possible_gate = default_bsr_set_without_rn[gate_name](*arguments)
gate_bsr = BlochSphereRotation(axis=gate.bsr.axis, angle=gate.bsr.angle, phase=gate.bsr.phase)
if possible_gate.bsr == gate_bsr:
return possible_gate
nx, ny, nz = gate.bsr.axis.value
return Rn(gate.qubit, nx=nx, ny=ny, nz=nz, theta=gate.bsr.angle, phi=gate.bsr.phase)
|