csookim / qibo_cskim

A framework for quantum computing
https://qibo.science
Apache License 2.0
0 stars 0 forks source link

Runtime Comparison #29

Closed csookim closed 1 month ago

csookim commented 1 month ago

Introduction

# output
qibo Trivial + SABRE   avg: 0.40797 std: 0.09014
qiskit Trivial + SABRE avg: 0.04401 std: 0.00765

Implementation

1. Qubit Mapping

Previous Approach

self._graph_qubits_names = [int(key[1:]) for key in self.initial_layout.keys()]
self._circuit_logical = list(range(len(self.initial_layout)))
self._physical_logical = list(self.initial_layout.values())

Problem

Updated Approach

self._p_qubit_names = list(self.initial_layout.keys())
self._p2l = list(self.initial_layout.values())
self._l2p = [0] * len(self._p2l)
for i, l in enumerate(self._p2l):
    self._l2p[l] = i

Example

let
initial_layout = {"q0": 3, "q1":1, "q2":0, "q3":2}

then
_p2l = [3, 1, 0, 2]    # physical qubit number i matches logical qubit number _p2l[i]
_l2p = [2, 1, 3, 0]    # logical qubit number i matches physical qubit number _l2p[i] 
_p_qubit_names = ["q0", "q1", "q2", "q3"]  # physical qubit number i has name _p_qubit_names[i]

2. Temporary Circuit

Previous Approach

temporary_circuit = CircuitMap(
            initial_layout=self.circuit.initial_layout,
            circuit=Circuit(len(self.circuit.initial_layout)),
            blocks=self.circuit.circuit_blocks,
        )

Problem

Updated Approach

        self._temporary = temp
        if self._temporary:     # if temporary circuit, no need to store the blocks
            return

        ...
        ### add the real SWAP gate, not a temporary circuit
        if not self._temporary:
            self._routed_blocks.add_block(
                Block(qubits=physical_swap, gates=[gates.SWAP(*physical_swap)])
            )
            self._swaps += 1

3. Qubits of a Block in the front_layer

Previous Approach

def _get_dag_layer(self, n_layer):
        """Return the :math:`n`-topological layer of the dag."""
        # node[0] is the gate number
        return [node[0] for node in self._dag.nodes(data="layer") if node[1] == n_layer]

Problem

Updated Approach

### additionally save the qubit pairs that the gates are acting on
    for i in range(len(gates_qubits_pairs)):
        dag.nodes[i]["qubits"] = gates_qubits_pairs[i]

4. Additional

Evaluation

qibo Trivial + SABRE   avg: 0.06699 std: 0.0163
qiskit Trivial + SABRE avg: 0.04346 std: 0.00588