Skip to content

Commit

Permalink
feat: added wire names to parser
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoLiegiBastonLiegi committed Feb 26, 2024
1 parent 6485715 commit c25ad35
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/qibo/_openqasm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Qibo wrapper for QASM 3.0 parser."""

from itertools import repeat
from typing import Union

import numpy as np
Expand Down Expand Up @@ -163,7 +164,12 @@ def to_circuit(
self.c_registers.update({name: list(range(size))})
else:
raise_error(RuntimeError, f"Unsupported {type(statement)} statement.")
circ = qibo.Circuit(nqubits, accelerators, density_matrix)
circ = qibo.Circuit(
nqubits,
accelerators,
density_matrix,
wire_names=self._construct_wire_names(),
)
for gate in gates:
circ.add(gate)
self._reorder_registers(circ.measurements)
Expand Down Expand Up @@ -268,3 +274,14 @@ def _reorder_registers(self, measurements):
gates according to the classical registers order defined in the QASM program."""
for meas in measurements:
meas.target_qubits = [self.c_registers[meas.register_name].pop(0)]

def _construct_wire_names(self):
"""Builds the wires names from the declared quantum registers."""
wire_names = []
for reg_name, reg_qubits in self.q_registers.items():
wires = sorted(
zip(repeat(reg_name, len(reg_qubits)), reg_qubits), key=lambda x: x[1]
)
for wire in wires:
wire_names.append(f"{wire[0]}{wire[1]}")
return wire_names

0 comments on commit c25ad35

Please sign in to comment.