跳转至

SymbolicPhase

QuICT.qcda.optimization.clifford_rz_optimization.symbolic_phase

SymbolicBasicGate

SymbolicBasicGate(controls: int, targets: int, params: int, type_: GateType, matrix_type: MatrixType = MatrixType.normal, pargs: list = None, precision: str = 'double', is_original_gate: bool = False)

Bases: BasicGate

Source code in QuICT/qcda/optimization/clifford_rz_optimization/symbolic_phase.py
def __init__(self,
             controls: int,
             targets: int,
             params: int,
             type_: GateType,
             matrix_type: MatrixType = MatrixType.normal,
             pargs: list = None,
             precision: str = "double",
             is_original_gate: bool = False):

    if pargs is None:
        pargs = []
    super().__init__(controls, targets, params, type_, matrix_type, pargs, precision, is_original_gate)
permit_element
permit_element(element) -> bool

judge whether the type of a parameter is int/float/complex

for a quantum gate, the parameter should be int/float/complex

Parameters:

  • element

    the element to be judged

Returns:

  • bool ( bool ) –

    True if the type of element is int/float/complex

Source code in QuICT/qcda/optimization/clifford_rz_optimization/symbolic_phase.py
def permit_element(self, element) -> bool:
    """ judge whether the type of a parameter is int/float/complex

    for a quantum gate, the parameter should be int/float/complex

    Args:
        element: the element to be judged

    Returns:
        bool: True if the type of element is int/float/complex
    """
    if not isinstance(element, list):
        element = [element]

    for el in element:
        if not isinstance(el, (int, float, complex, np.complex64, SymbolicPhase)):
            raise TypeError("basicGate.targs", "int/float/complex/SymbolicPhase", type(el))

SymbolicPhase

SymbolicPhase()

Symbolic phase expression.

Source code in QuICT/qcda/optimization/clifford_rz_optimization/symbolic_phase.py
def __init__(self):
    self.var_dict = {}
    self.const = 0
copy
copy() -> SymbolicPhase

Get a copy of this SymbolicPhase.

Returns:

Source code in QuICT/qcda/optimization/clifford_rz_optimization/symbolic_phase.py
def copy(self) -> "SymbolicPhase":
    """
    Get a copy of this SymbolicPhase.

    Returns:
        SymbolicPhase: a copy
    """
    ret = SymbolicPhase()
    for k, v in self.var_dict.items():
        ret.var_dict[k] = v.copy()
    ret.const = self.const
    return ret
evaluate
evaluate() -> float

Evaluate the value of this SymbolicPhase. If it contains any undetermined variable, it will return float('inf').

Returns:

  • float ( float ) –

    value of this SymbolicPhase

Source code in QuICT/qcda/optimization/clifford_rz_optimization/symbolic_phase.py
def evaluate(self) -> float:
    """
    Evaluate the value of this SymbolicPhase.
    If it contains any undetermined variable, it will return float('inf').

    Returns:
        float: value of this SymbolicPhase
    """
    ret = self.const
    for var, coef in self.var_dict.values():
        if np.isclose(coef, 0):
            continue
        if var.phase is None:
            return float('inf')
        ret += var.phase * coef
    return ret

SymbolicPhaseVariable

SymbolicPhaseVariable(label)

Symbolic phase variable.

Source code in QuICT/qcda/optimization/clifford_rz_optimization/symbolic_phase.py
def __init__(self, label):
    self.phase = None
    self.label = label