[FEATURE] Implement Circuit Segmentation via `.segment()` Method
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
Línea de trabajo
Start from QasmModule and loads in the pyqasm package to see how a parsed program stores its qubit registers and gate statements. The new .segment() method needs a union-find over qubits joined by multi-qubit gates, then emits one QasmModule per component with remapped __PYQASM_SEGMENT_<idx>__ registers. Done means the example in the issue produces the two shown segments and that measurements or classical controls raise an error. The single-qubit edge case and the return-type question are unresolved in the thread, so confirm them with the maintainers first.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Feature Description
-
Introduce a .segment() method to
pyqasm.QasmModulethat partitions quantum circuits into independent segments where no entanglement exists between segments. -
Each segment is returned as a standalone
QasmModuleobject containing:- Remapped qubit registers (e.g., PYQASM_SEGMENT_0[i])
- Gates acting exclusively on the segment's qubits
-
Key constraints:
- We use entangling gates to define an "independently executable segment". Raises an error if the circuit contains measurements or classical controls (unsupported in v1).
- Qubit order in new registers follows first occurrence in the original circuit.
Motivation
- Parallel Execution: Enables independent segment execution across multiple QPUs.
- Resource Optimization: Splits large circuits for execution on smaller devices.
- Error Containment: Isolates quantum errors to individual segments.
Implementation (Optional)
Preprocessing:
-
Validate absence of measurements/classical controls.
-
Construct a qubit connectivity graph using multi-qubit gates (edges connect interacting qubits).
Segmentation Algorithm:
-
Identify connected components in the graph → segments. Should essentially be a disjoint set union amongst all the qubits present in our program. Inspired by the
BlockSplitterin qiskit'sdag_circuit.collect_blocks -
For each segment:
-
Create a new register
qubit[N] __PYQASM_SEGMENT_<idx>__(N = segment qubit count). -
Remap original qubits to new register indices ordered by first gate occurrence.
-
Module Generation:
- Clone original module headers (OPENQASM 3.0, includes).
- Replace original gates with remapped operations.
- Preserve gate order within segments.
Edge Cases:
- All Single-qubit gates → Divide into a default segment count (say 10) as all qubits are disjoint
- Empty circuits → No OP
Example flow
from pyqasm import loads
qasm_code = """
OPENQASM 3.0;
qubit[4] q;
h q[0];
cx q[0], q[1];
h q[2];
cx q[2], q[3];
"""
module = loads(qasm_code)
segments = module.segment() # Returns 2 QasmModules
print(segments[0])
# Output:
# OPENQASM 3.0;
# qubit[2] __PYQASM_SEGMENT_0__;
# h __PYQASM_SEGMENT_0__[0];
# cx __PYQASM_SEGMENT_0__[0], __PYQASM_SEGMENT_0__[1];
print(segments[1])
# Output:
# OPENQASM 3.0;
# qubit[2] __PYQASM_SEGMENT_1__;
# h __PYQASM_SEGMENT_1__[0];
# cx __PYQASM_SEGMENT_1__[0], __PYQASM_SEGMENT_1__[1];
This is a first draft where we return a list of modules but can potentially be changed in-place addition of these segments to existing module
- Lenguaje dominante
- Python
- Estrellas
- 29
- Forks
- 33
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de qBraid/pyqasm
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día
-
enhancement error-handling program-validation
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.pyPosiblemente ocupada @danielgaskins la tomó hace 7 días. Abiertoenhancement qasm2
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
qBraid/pyqasm#447 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASMPosiblemente ocupada @Jah-yee la tomó hace 15 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
qBraid/pyqasm#438 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lostPosiblemente ocupada @tonycoder-hub la tomó hace 9 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 22/100
qBraid/pyqasm#436 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de qBraid/pyqasm
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ansys/pyansys-common-mcp#213 ·
Los mantenedores suelen responder en 3 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
freedomofpress/dangerzone#1594 ·
Los mantenedores suelen responder en 3 días
-
priority:P1 status:in-review type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
randomparity/kdive#3317 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area:ci
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
mesonbuild/meson#16281 ·
Los mantenedores suelen responder en 1 día