跳转至

CircuitPath

QuICT.qcda.utility.fidelity_estimator.circuit_path

CircuitPath

CircuitPath(path: tuple = None, max_step: int = 1, has_full=True)

Parameters:

  • path(tuple[(BasicGate, (r_type)]) –

    a k-step path with each element in the

  • max_step(int)

    max step of the path.

  • has_full(bool)

    has full path or not. Has full path means

Info: r_type in ["parallel", "next", "next2", "next3"]. Let cx be the example of two qubit gate. for cx gate and 1-qubit gate, next means connected on control qubit, next2 means connected on target qubit, for two cx gates, next means control connect target, next2 means target connect target, next3 means control connect target doubly. if the two qubit gate has two target qubits, then only next.

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def __init__(
        self,
        path: tuple = None,
        max_step: int = 1,
        has_full=True):
    """
    Args:
        path(tuple[(BasicGate, r_type)]): a k-step path with each element in the
        form of (gate_type, r_type).
        max_step(int): max step of the path.
        has_full(bool): has full path or not. Has full path means
        that this path consists of BasicGate, not GateType.
    Info:
        r_type in ["parallel", "next", "next2", "next3"].
        Let cx be the example of two qubit gate.
        for cx gate and 1-qubit gate, next means connected on control qubit,
        next2 means connected on target qubit,
        for two cx gates, next means control connect target, next2 means
        target connect target, next3 means control connect target doubly.
        if the two qubit gate has two target qubits, then only next.
    """
    self.path = []
    self.max_step = max_step
    self.full_path = []
    self.has_full = has_full
    self.type_list = ["parallel", "next", "next2", "next3"]
    if path is None or len(path) == 0:
        return
    assert len(path) <= self.max_step + 1, r"path too long"
    assert path[0][1] == "start", "first gate should be start type"

    for item in path:
        if self.has_full:
            self.path.append((item[0].type, item[1]))
            self.full_path.append((item[0], item[1]))
        else:
            self.path.append((item[0], item[1]))
add
add(item, r_type: str = 'next')

Parameters:

  • item(BasicGate (or GateType) –

    the gate or gate type to add

  • r_type(str)

    r_type in ["parallel", "next", "next2", "next3"]

Returns: bool: succeed or not

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def add(self, item, r_type: str = "next"):
    """
    Args:
        item(BasicGate or GateType): the gate or gate type to add
        r_type(str): r_type in ["parallel", "next", "next2", "next3"]
    Returns:
        bool: succeed or not
    """
    if self.has_full:
        return self.add_gate(item, r_type)
    else:
        return self.add_gatetype(item, r_type)
add_gate
add_gate(gate: BasicGate, r_type: str = 'next')

Parameters:

  • gate(BasicGate)

    gate to add

  • r_type(str)

    in ["start", "parallel", "next", "next2", "next3],

Returns: bool: succeed or not

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def add_gate(self, gate: BasicGate, r_type: str = "next"):
    """
    Args:
        gate(BasicGate): gate to add
        r_type(str): in ["start", "parallel", "next", "next2", "next3],
        only the first one can be "start".
    Returns:
        bool: succeed or not
    """
    gatetype = gate.type
    if len(self.path) > self.max_step:
        return False
    if len(self.path) > 0:
        assert r_type in self.type_list, r"r_type not in desired list!"
    else:
        assert r_type == "start", r"r_type not in desired list!"
    self.path.append((gatetype, r_type))
    self.full_path.append((gate, r_type))
    return True
add_gatetype
add_gatetype(gatetype: GateType, r_type: str = 'next')

Parameters:

  • gatetype(GateType)

    GateType to add

  • r_type(str)

    in ["start", "former", "parallel", "next", "next2", "next3],

Returns: bool: succeed or not

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def add_gatetype(self, gatetype: GateType, r_type: str = "next"):
    """
    Args:
        gatetype(GateType): GateType to add
        r_type(str): in ["start", "former", "parallel", "next", "next2", "next3],
        only the first one can be "start".
    Returns:
        bool: succeed or not
    """
    if len(self.path) > self.max_step:
        return False
    if len(self.path) > 0:
        assert r_type in self.type_list, r"r_type not in desired list!"
    else:
        assert r_type == "start", r"r_type not in desired list!"
    self.path.append((gatetype, r_type))
    return True
get_gate
get_gate(num)

Parameters:

  • num(int)

    index in this path

Returns: BasicGate if exists, and None if not

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def get_gate(self, num):
    """
    Args:
        num(int): index in this path
    Returns:
        BasicGate if exists, and None if not
    """
    if self.has_full:
        return self.full_path[num][0]
    else:
        return None
get_gate_type
get_gate_type(num)

Parameters:

  • num(int)

    index in this path

Returns: GateType

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def get_gate_type(self, num):
    """
    Args:
        num(int): index in this path
    Returns:
        GateType
    """
    return self.path[num][0]
get_r_type
get_r_type(num)

Parameters:

  • num(int)

    index in this path

Returns: str

Source code in QuICT/qcda/utility/fidelity_estimator/circuit_path.py
def get_r_type(self, num):
    """
    Args:
        num(int): index in this path
    Returns:
        str
    """
    return self.path[num][1]