跳转至

InstructionSet

QuICT.core.virtual_machine.InstructionSet

InstructionSet(two_qubit_gate: GateType, one_qubit_gates: List[GateType], one_qubit_rule: Union[str, callable] = None)

Bases: object

InstructionSet describes a set of gates(expectly to be universal set)

Instruction Set contains gates and some rules, which can be assigned by user.

Attributes:

  • two_qubit_gate (GateType) –

    the type of the two_qubit_gate

  • one_qubit_gates (list<GateType>) –

    the types of the one_qubit_gate

  • one_qubit_gates_fidelity (Union[float, Dict, List]) –

    The fidelity for single qubit quantum gate. Defaults to None.

  • one_qubit_rule (Union[str, callable]) –

    rules to transform SU(2) into instruction set

Source code in QuICT/core/virtual_machine/instruction_set.py
def __init__(
    self,
    two_qubit_gate: GateType,
    one_qubit_gates: List[GateType],
    one_qubit_rule: Union[str, callable] = None
):
    self.two_qubit_gate = two_qubit_gate
    self.one_qubit_gates = one_qubit_gates
    self.__one_qubit_rule = None
    if one_qubit_rule is not None:
        self.register_one_qubit_rule(one_qubit_rule)

    self.__two_qubit_rule_map = {}

gates property

gates: list

Return the list of GateType in current Instruction Set.

one_qubit_rule property

one_qubit_rule

the rule of decompose 2*2 unitary into target gates

If not assigned by the register_one_qubit_rule method, some pre-implemented method would be chosen corresponding to the one_qubit_gates. An Exception will be raised when no method is chosen.

Returns:

  • callable

    the corresponding rule

register_one_qubit_rule

register_one_qubit_rule(one_qubit_rule: Union[str, callable])

register one-qubit gate decompostion rule

Parameters:

  • one_qubit_rule(callable)

    decompostion rule, you can define your self rule function or use one of [zyz_rule, zxz_rule, hrz_rule, xyx_rule, ibmq_rule, u3_rule].

Source code in QuICT/core/virtual_machine/instruction_set.py
def register_one_qubit_rule(self, one_qubit_rule: Union[str, callable]):
    """ register one-qubit gate decompostion rule

    Args:
        one_qubit_rule(callable): decompostion rule, you can define your self rule function or use one of
            [zyz_rule, zxz_rule, hrz_rule, xyx_rule, ibmq_rule, u3_rule].
    """
    assert isinstance(one_qubit_rule, (str, FunctionType)), \
        TypeError("Unsupport Type, should be one of [string, Callable].")
    self.__one_qubit_rule = one_qubit_rule

register_two_qubit_rule_map

register_two_qubit_rule_map(two_qubit_rule: callable, source: GateType)

register rule which transforms from source gate into target gate

Parameters:

  • two_qubit_rule(callable)

    the transform rule

  • source(GateType)

    the type of source gate

Source code in QuICT/core/virtual_machine/instruction_set.py
def register_two_qubit_rule_map(self, two_qubit_rule: callable, source: GateType):
    """ register rule which transforms from source gate into target gate

    Args:
        two_qubit_rule(callable): the transform rule
        source(GateType): the type of source gate
    """
    assert isinstance(source, GateType)
    self.two_qubit_rule_map[source] = [(source, two_qubit_rule)]

select_transform_rule

select_transform_rule(source)

choose a rule which transforms source gate into target gate(2-qubit)

Parameters:

  • source(GateType)

    the type of source gate

Returns:

  • callable

    the transform rules

Source code in QuICT/core/virtual_machine/instruction_set.py
def select_transform_rule(self, source):
    """ choose a rule which transforms source gate into target gate(2-qubit)

    Args:
        source(GateType): the type of source gate

    Returns:
        callable: the transform rules
    """
    assert isinstance(source, GateType)
    # If registered, no more check needed
    if source in self.two_qubit_rule_map.keys():
        return self.two_qubit_rule_map[source]

    source_cate = None
    target_cate = None
    for cate in self.two_qubit_categories.keys():
        if source in self.two_qubit_categories[cate]:
            source_cate = cate
        if self.two_qubit_gate in self.two_qubit_categories[cate]:
            target_cate = cate
    if source_cate is None or target_cate is None:
        raise ValueError(f'Transform rule not found between {source.name} and {self.two_qubit_gate.name}')

    # If source and target are in the same category
    if source_cate == target_cate:
        # Furthermore, if source or target is the key gate, a direct transform rule could be selected
        if source == source_cate or self.two_qubit_gate == target_cate:
            self.two_qubit_rule_map[source] = [
                (source, f"{source.name}2{self.two_qubit_gate.name}_rule")
            ]
        # Otherwise, they need to be transformed to the key gate first
        else:
            self.two_qubit_rule_map[source] = [
                (source, f"{source.name}2{source_cate.name}_rule"),
                (target_cate, f"{target_cate.name}2{self.two_qubit_gate.name}_rule")
            ]
    # Otherwise, we need the two key gates as a tranfer
    else:
        self.two_qubit_rule_map[source] = []
        if source != source_cate:
            self.two_qubit_rule_map[source].append(
                (source, f"{source.name}2{source_cate.name}_rule")
            )
        self.two_qubit_rule_map[source].append(
            (source_cate, f"{source_cate.name}2{target_cate.name}_rule")
        )
        if self.two_qubit_gate != target_cate:
            self.two_qubit_rule_map[source].append(
                (target_cate, f"{target_cate.name}2{self.two_qubit_gate.name}_rule")
            )

    return self.two_qubit_rule_map[source]