Skip to content

Conversation

arunjmoorthy
Copy link
Collaborator

Summary of changes

Fixes issue 217 by adding a merge function, so two QasmModule objects can be combined into one. The merge function unrolls both modules and creates a single qubit declaration. This function appends the second QasmModule object with the correct index offsets and returns a Qasm3Module.

The test_merge.py file is added, which has a few examples of merging two modules, using the merge function.

Copy link
Contributor

👋 Hey there! It looks like the changelog might need an update.

Please take a moment to edit the CHANGELOG.md with:

  • A brief, one-to-two sentence summary of your changes.
  • A link back to this PR for reference.
  • (Optional) A small working example if you've added new features.

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 72.51908% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/modules/base.py 39.62% 32 Missing ⚠️
src/pyqasm/modules/qasm2.py 95.00% 2 Missing ⚠️
src/pyqasm/modules/qasm3.py 94.73% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!


assert "qubit[3] __PYQASM_QUBITS__;" in merged_text
assert "measure __PYQASM_QUBITS__[2];" in merged_text
assert "barrier __PYQASM_QUBITS__" in merged_text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert "barrier __PYQASM_QUBITS__" in merged_text
assert "barrier __PYQASM_QUBITS__[0]" in merged_text

merged_text = str(merged)

assert "qubit[3] __PYQASM_QUBITS__;" in merged_text
assert "measure __PYQASM_QUBITS__[2];" in merged_text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the structure of the measurement statements? I believe the merged qasm should be like -

OPENQASM 3.0;
include "stdgates.inc";
qubit[3] __PYQASM_QUBITS__;
// Module A
bit[1] ca;
h __PYQASM_QUBITS__[0];
barrier __PYQASM_QUBITS__[0];
ca[0] = measure __PYQASM_QUBITS__[0];

// Module B
bit[2] cb;
x __PYQASM_QUBITS__[1];
cb[1] = measure __PYQASM_QUBITS__[1];

Copy link
Member

@TheGupta2012 TheGupta2012 Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the verification functions from the tests/utils.py file? We have already implemented a lot of robust checks in that file which you are implementing from scratch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants