dqcnac.nonlocal_gate_scheduling.nonlocal_gate_schedule module

The Nonlocal gates scheduler module.

class dqcnac.nonlocal_gate_scheduling.nonlocal_gate_schedule.NonlocalGateSchedule(network: Network, nodes_mapping: Dict[qiskit.circuit.Qubit, str], use_teleport: bool = True)[source]

Bases: object

A nonlocal gates’ scheduler class.

__init__(network: Network, nodes_mapping: Dict[qiskit.circuit.Qubit, str], use_teleport: bool = True)[source]

Initialize the remote gates’ scheduler.

Parameters:
  • network – the network to use for remote operations.

  • nodes_mapping

  • use_teleport – whether to use teledata operations or not.

add_gate(gate, executed: List[Tuple[int, qiskit.dagcircuit.DAGOpNode]], times: Dict[qiskit.circuit.Qubit, int], qargs: List[qiskit.circuit.Qubit] = None)[source]

Add a scheduled gate to the compilation state.

Parameters:
  • gate – the gate to add

  • qargs – the qubits on which the gate acts

  • executed – the current list of executed gates

  • times – the times of last usage for each qubit

static circuit_cost(executed: List[Tuple[int, qiskit.dagcircuit.DAGOpNode]]) → int[source]

Compute the cost of the circuit regarding consumed ebits.

Parameters:

executed – the list of executed gates

Returns:

the estimated cost of the circuit

comp_cover_succ(to_cover: qiskit.dagcircuit.DAGOpNode, best_cost: Cover, state: State, to_remove: Set[qiskit.dagcircuit.DAGOpNode], remote_ops_count: int, new_qargs: List[qiskit.circuit.Qubit], e1: List[qiskit.circuit.Qubit], _e1: List[qiskit.circuit.Qubit], e2: List[qiskit.circuit.Qubit], _e2: List[qiskit.circuit.Qubit])[source]

Check if cat-ent can cover more than one gate.

Parameters:
  • to_cover – the gate to cover

  • best_cost – the cost of the cat-ent

  • state – the current compilation state

  • to_remove – a set of gates to remove form the gates’ list, already covered by previous compilation steps

  • remote_ops_count – the number of remote operations scheduled

  • new_qargs – the qubits on which the covered gate will act

  • e1 – the ebits used for the cat-ent, node1 to node2

  • _e1 – the ebits used for the cat-ent, node1 to middle, only for migration on a middle node

  • e2 – the ebits used for the cat-ent, node2 to node1

  • _e2 – the ebits used for the cat-ent, node2 to middle, only for migration on a middle node

comp_dis_ent(best_cost: Cover, state: State, to_cover: qiskit.dagcircuit.DAGOpNode, e2: List[qiskit.circuit.Qubit], _e2: List[qiskit.circuit.Qubit])[source]

Add cat-disent after gate (to_cover).

Parameters:
  • best_cost – the cist of the cat-disent

  • state – the current compilation state

  • to_cover – the gate covered

  • e2 – the ebits used for the cat-disent, node2 to node1

  • _e2 – the ebits used for the cat-disent, only for migration on a middle node

comp_ent(state: State, to_cover: qiskit.dagcircuit.DAGOpNode, to_remove: Set[qiskit.dagcircuit.DAGOpNode], best_cost: Cover) → Tuple[List[qiskit.circuit.Qubit] | None, List[qiskit.circuit.Qubit] | None, List[qiskit.circuit.Qubit] | None, List[qiskit.circuit.Qubit] | None, List[qiskit.circuit.Qubit] | None][source]

Add cat-ent to cover gate (to_cover)

Parameters:
  • state – the current compiled state

  • to_cover – the gate to cover

  • to_remove – a list of gates to remove from the gates’ list, already covered by previous compilation steps

  • best_cost – the cost of the cat-ent

Returns:

the qubits which the covered gate acts, the ebits used to perform the cat-ent

comp_for(gates: Dict[qiskit.dagcircuit.DAGOpNode, None], state: State, uncovered: Set[qiskit.dagcircuit.DAGOpNode], to_remove: Set[qiskit.dagcircuit.DAGOpNode], remote_ops_count: int, dag_circuit: qiskit.dagcircuit.DAGCircuit, to_cover: qiskit.dagcircuit.DAGOpNode | None, best_cost: int)[source]

Search for remote gate to cover

Parameters:
  • gates – the list of gates in the circuit

  • state – the current compiled state

  • uncovered – the list of uncovered gates

  • to_remove – a list of gates to remove form the gates’ list, already covered by previous compilation steps

  • remote_ops_count – the number of remote operations already scheduled

  • dag_circuit – the circuit to compile

  • to_cover – the next gate to cover

  • best_cost – the cost of the coverage

Returns:

the best coverage, either teleport or telegate, and the cost of the coverage

comp_post_process(state: State, gates: Dict[qiskit.dagcircuit.DAGOpNode, None], to_remove: Set[qiskit.dagcircuit.DAGOpNode], uncovered: Set[qiskit.dagcircuit.DAGOpNode])[source]

Update list of uncovered gates.

Parameters:
  • state – the current compilation state

  • gates – the list of gates in the circuit

  • to_remove – a list of gates to remove form the gates’ list, already covered by previous compilation steps

  • uncovered – the list of uncovered gates

comp_preprocess(dag_circuit: qiskit.dagcircuit.DAGCircuit, state: State, previous: List[State]) → Tuple[Dict[qiskit.dagcircuit.DAGOpNode, None], Set[qiskit.dagcircuit.DAGOpNode], int][source]

Preprocess before compilation with cat-ent. Update list of uncovered and covered gates

Parameters:
  • dag_circuit – the dag circuit to compile

  • state – the current compilation state

  • previous – a list of previously compiled states, possibly derived from previous evaluations during coverage of other gates

Returns:

the list of gates, the update lists of uncovered and covered gates

comp_while(uncovered: Set[qiskit.dagcircuit.DAGOpNode], stop: int, gates: Dict[qiskit.dagcircuit.DAGOpNode, None], state: State, dag_circuit: qiskit.dagcircuit.DAGCircuit, max_cost: int, previous: List[State], compiled: State, mig_found: bool, post_tel: bool = False) → State[source]

Compile portion of circuit with telegates.

Parameters:
  • uncovered – the list of uncovered gates

  • stop – the number of gates we will try to cover

  • gates – the list of gates in the circuit

  • state – the current compilation state

  • dag_circuit – the circuit to compile

  • max_cost – the maximum cost allowed for covering a gate

  • previous – a list of previously compiled states, possibly derived from previous evaluations during coverage of other gates

  • compiled – the compilation state to update

  • mig_found – signal if the coverage of at least one gate was possible

  • post_tel – signal if we are trying to compile after a teleport operation

Returns:

the updated compilation state

compile(dag_circuit: qiskit.dagcircuit.DAGCircuit, state: State, stop_early: bool = False, previous: List[State] = None) → Tuple[State, State, List[State]][source]

Compile circuit with telegates.

Parameters:
  • dag_circuit – the circuit to compile

  • state – the current compilation state

  • stop_early – signal if we want to put a limit on the gates covered by a single cat-ent

  • previous – a list of previously compiled states, possibly derived from previous evaluations during coverage of other gates

Returns:

the updated compilation state

compile_multi_gate(multi_gate: qiskit.dagcircuit.DAGOpNode, state: State, old_qregs: Dict[qiskit.circuit.Qubit, qiskit.circuit.Qubit])[source]

Compile everything in a multi-gate Multi-gate could have many non-local gates, but they shouldn’t break each other

Parameters:
  • multi_gate – the multi-gate to compile

  • state – the current state

  • old_qregs – the old qregs mapping

cost(dag_circuit: qiskit.dagcircuit.DAGCircuit, gate: qiskit.dagcircuit.DAGOpNode, time: int, uncovered: Set[qiskit.dagcircuit.DAGOpNode], state: State) → Cover[source]

Select best migration.

Parameters:
  • dag_circuit – the circuit to compile

  • gate – the gate covered

  • time – the time at which we would like to execute the gate

  • uncovered – a list of uncovered gates

  • state – the current compilation state

Returns:

the best coverage found

find_migrations(gate: qiskit.dagcircuit.DAGOpNode, nodes_mapping: Dict[qiskit.circuit.Qubit, str], mappings: Dict[qiskit.circuit.Qubit, qiskit.circuit.Qubit]) → List[Cover][source]

Find possible migrations.

Parameters:
  • gate – the gate to cover

  • nodes_mapping – the current nodes mapping

  • mappings – the current mapping

Returns:

a list of possible covers

find_teleports(gate: qiskit.dagcircuit.DAGOpNode, state: State) → List[Cover][source]

Find possible teledata operations to cover a gate

Parameters:
  • gate – the gate to cover

  • state – the current compilation state

Returns:

a list of possible teledata operations

get_min_ebit(state: State, node1: str, node2: str, exclude: Set = None) → qiskit.circuit.Qubit[source]

Find the least used ebit from node1 to node 2.

Parameters:
  • state – the current compilation state

  • node1 – the first node

  • node2 – the second node

  • exclude – ebits to exclude from the search

Returns:

the ebit

get_teleport(gate: qiskit.dagcircuit.DAGOpNode, state: State) → Tuple[int, State, List][source]

Compile with teleports

Parameters:
  • gate – the gate to cover

  • state – the current compiled state

Returns:

the cost of the teleport, the consequent compilation state, and an empty list

is_covered(gate: qiskit.dagcircuit.DAGOpNode, migration: Cover, time1: int, times: Dict[qiskit.circuit.Qubit, int], covered: Set[qiskit.dagcircuit.DAGOpNode], mapping: Dict[qiskit.circuit.Qubit, qiskit.circuit.Qubit], time2: int = None) → bool[source]

Check if migration covers the gate, check also for coverage based on timing

Parameters:
  • gate – the gate to check coverage for

  • migration – the migration to check coverage for

  • time1 – the time of the first migration

  • times – the times of last usage for each qubit

  • covered – the set of covered gates

  • mapping – the mapping of qubits to qubits

  • time2 – the time of the second migration

Returns:

True if migration covers the gate, False otherwise

static local_op(qargs: List[qiskit.circuit.Qubit], nodes_mapping: Dict[qiskit.circuit.Qubit, str]) → bool[source]

Check if an operation is local or not.

Parameters:
  • qargs – the qubits on which the operation acts

  • nodes_mapping – the current mapping of qubits to nodes in a network

Returns:

True if the operation is local, False otherwise

run(dag_circuit: qiskit.dagcircuit.DAGCircuit, gate_grouping: bool, count_non_local_gates: bool = False) → Tuple[State, Dict[qiskit.circuit.Qubit, qiskit.circuit.Qubit]][source]

Run the remote operation scheduler over a circuit.

Parameters:
  • dag_circuit – the circuit to schedule

  • gate_grouping – whether to group gates

  • count_non_local_gates – whether to count non-local gates

Returns: The state of compilation after scheduling and the final mapping of the qubits

tel_compile(dag_circuit: qiskit.dagcircuit.DAGCircuit, state: State, stop_early: bool = False) → Tuple[State, List[State]][source]

Compile circuit with telegates, after a teleport operation.

Parameters:
  • dag_circuit – the circuit to compile

  • state – the current compilation state

  • stop_early – signal if we want to put a limit on the gates covered by a single cat-ent

Returns:

the updated compilation state

tel_cov_succ(state: State, teleport: Cover, gate: qiskit.dagcircuit.DAGOpNode, e1: List[qiskit.circuit.Qubit])[source]

Check if teleport can cover more than one gate

Parameters:
  • state – the current compilation state

  • teleport – the teleport operation

  • gate – the gate covered by the teleport

  • e1 – the list of ebits used for the teleport

tel_for(teleports: List[Cover], state: State, gate: qiskit.dagcircuit.DAGOpNode, cost: int) → Tuple[int, State][source]

Search for best teleport

Parameters:
  • teleports – the possible teleport operations

  • state – the current compilation state

  • gate – the gate to cover

  • cost – the cost

Returns:

the cost of the best teleport and the consequent compilation state

tel_post_proces(_state: State, temp_nodes_mapping: Dict[qiskit.circuit.Qubit, str], temp_mapping: Dict[qiskit.circuit.Qubit, qiskit.circuit.Qubit], temp_timed_tele_list: List[Dict[int, int]], temp_executed: List[Tuple[int, qiskit.dagcircuit.DAGOpNode]], temp_times: Dict[qiskit.circuit.Qubit, int]) → Tuple[State, State][source]

Update compilation state after teleport

Parameters:
  • _state – the current compilation state

  • temp_nodes_mapping – the new nodes mapping

  • temp_mapping – the new mapping

  • temp_timed_tele_list – the new rimed_tele_list

  • temp_executed – the new executed list

  • temp_times – the new times

Returns:

the new state and a copy of it for further processing

tel_tel(state: State, teleport: Cover, gate: qiskit.dagcircuit.DAGOpNode) → List[qiskit.circuit.Qubit][source]

Add teleport to executed gates.

Parameters:
  • state – the current compilation state

  • teleport – the teleport to add

  • gate – the gate covered by the teleport operation

Returns:

the list of ebits used for the teleport