Skip to content

[FEATURE] Implement a .merge method for QasmModule #217

@TheGupta2012

Description

@TheGupta2012

Feature Description

Implement a.merge() method with automatic unrolling and register consolidation.

  • Purpose:
    Merge two QasmModule objects into a single module, handling all register consolidation and unrolling transparently.
  • Consolidation & Unrolling:
    • All register consolidation and unrolling is performed automatically during the merge.
    • Uses the existing .unroll(device_qubits) method to ensure both modules are unrolled and consolidated before merging.
  • User Experience:
    • The user only needs to call .merge() on one module, passing the other as an argument.
    • No manual unrolling or consolidation is required.
  • Output:
    • Returns a new, merged module (preferred for immutability).
    • All qubit and classical registers are consolidated into __PYQASM_QUBITS__ and __PYQASM_CLASSICAL__.

Implementation (Optional)

  1. Unroll and Consolidate Both Modules:
    • Call .unroll(device_qubits=...) on both modules before merging.
    • If device_qubits is not specified, use a default large enough to hold all qubits.
    • This ensures all registers are consolidated and unrolled.
  2. Merge Gates and Operation History:
    • Append gates from the second module after the first.
    • Combine operation history lists.
  3. Consolidate the Merged Module (Optional, but Safe):
    • If the merge could introduce new registers (unlikely if both are already consolidated), perform a final consolidation.
    • This step is mostly redundant but ensures robustness.
  4. Return the New Module:
    • Return a new QasmModule with the merged content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestllm-assistedUsed LLMs to fine tune issue description.transformationRelated to qasm program transformation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions