qat.pbo.GraphCircuit

class qat.pbo.GraphCircuit

Data structure based on a Directed Acyclic Graph (DAG) representation.

This class is useful to remove / replace subcircuits.

Keyword Arguments
  • gate_set (GateSet, optional) – Gate set used to cast this object into a Circuit

  • **kwargs (**kwargs, optional) – the method to_circ() use an object of type Program to cast this object into a Circuit. These extra keyword arguments are passed to the constructor of the Program class

load_circuit()

Load a circuit (init the current object)

Parameters
  • circuit (qat.core.Circuit) – circuit

  • main_only (optional, bool) – if set to True, only the main body of the Circuit will be integrated over. Defaults to False

  • max_depth (optional, int) – maximum depth for integrating gates

replace_pattern()

Find a pattern in the graph and replace it by another one

Warning

Only the first occurrence of the pattern is replaced. This function needs to be called several times to effectively replace all the occurrences of the pattern.

Parameters
  • old_pattern (list<Gate>) –

    pattern description one wants to remove from the circuit. A gate is composed of a name, a set of qubits and optionally parameters:

    • a name is str or a qat.pbo.GateName

    • a set of qubits is list<int> or set<int>

    • a parameter is a qat.pbo.VAR or a python object (int, float, str, …)

    For instance, the pattern [('CNOT', [1, 2]), ('CNOT', {1, 3}), ('RZ', [1], x)] describes:

    • a pattern is composed of two consecutives CNOT gates followed by a RZ gate

      • The qubits of the second gate are in a SET because the order of the qubits does not matter

        Warning

        A set of size n increase the complexity (multiply the complexity by \(n!\)). Please, minimize the number of set.

      • The qubits order of the second gate is important, a LIST is used

    • the first gate act on the qubits [1, 2]

    • the second gate act on the qubits {1, 3} (the order does not matter)

    • the third gate act on the qubit [1] and have a parameter x (instance of VAR)

    Warning

    The graph generated by this pattern MUST be connected.

  • new_pattern (list<tuple(str, list<int>, VAR...)>) –

    pattern replacing the old_pattern.

    Warning

    Qubits must be ordered. The set of qubits of the new pattern should be type list<int>.

  • pos (int, optional) –

    select the position of the pattern in the graph:

    • default No position imposed

    • int index of the first gate of the pattern in the graph

    • all replace all the found positions

  • begin (list<int>, optional) – list of qubits which go through no gates between the beginning of the circuit and the pattern

  • end (list<int>, optional) – list of qubits which go through no gates between the pattern and the ending of the circuit

Returns

True if a pattern has been found and replaced

Return type

bool

find_pattern()

Find a pattern in the circuit

Warning

Patterns are not necessarily disjoint. Some of them may overlap.

Parameters

pattern (list<Gate>) –

pattern description. A gate is composed of a name, a set of qubits and optionally parameters:

  • a name is str or a qat.pbo.GateName

  • a set of qubits is list<int> or set<int>

  • a parameter is a qat.pbo.VAR or a python object (int, float, str, …)

For instance, the pattern [('CNOT', [1, 2]), ('CNOT', {1, 3}), ('RZ', [1], x)] describes:

  • a pattern is composed of two consecutives CNOT gates followed by a RZ gate

  • the first gate act on the qubits [1, 2]

  • the second gate act on the qubits {1, 3} (the order does not matter)

  • the third gate act on the qubit [1] and have a parameter x (instance of VAR)

Warning

The graph generated by this pattern MUST be connected

Returns

position of the pattern in the graph

Return type

list<int>

count_pattern()

Count number of pattern occurrences in the graph

Parameters

pattern (list<Gate>) –

pattern description. A gate is composed of a name, a set of qubits and optionally parameters:

  • a name is str or a qat.pbo.GateName

  • a set of qubits is list<int> or set<int>

  • a parameter is a qat.pbo.VAR or a python object (int, float, str, …)

Returns

number of occurrences

Return type

int

add_abstract_gate()

Define abstract gate

Parameters

abstract_gate (AbstractGate) –

to_circ()

Function to transform this graph into a Circuit object

Parameters

kwargs – passed to the to_circ() method of the Program object used internally

Returns

Circuit