⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@rwakizaka
Copy link
Contributor

@rwakizaka rwakizaka commented Dec 10, 2025

Summary

When outputting quantum circuits in QASM3, the names of classical registers specified during circuit construction are preserved in the output.

Details and comments

We can specify a register name to add a quantum or classical register to a circuit like this:

auto qreg1 = QuantumRegister(2, std::string("q1"));
auto qreg2 = QuantumRegister(1, std::string("q2"));
auto creg1 = ClassicalRegister(2, std::string("c1"));
auto creg2 = ClassicalRegister(1, std::string("c2"));
QuantumCircuit circ(std::vector<QuantumRegister>({qreg1, qreg2}), std::vector<ClassicalRegister>({creg1, creg2}));

circ.measure(qreg2, creg2);
circ.measure(qreg1, creg1);

In the current Qiskit C++ implementation, multiple registers are combined into a single large register and their indices are adjusted, similar to the internal representation of the Qiskit C API. For example, the circuit above is output as follows:

qubit[3] q;
bit[3] c;
c[2] = measure q[2];
c[0] = measure q[0];
c[1] = measure q[1];

As a result, users have to determine which register corresponds to which index from the output, but this is obviously not intuitive. This PR resolves that issue, ensuring the QASM3 representation respects the classical register names specified by the user. For example, the circuit above will now be output as follows:

qubit[3] q;
bit[2] c1;
bit[1] c2;
c2[0] = measure q[2];
c1[0] = measure q[0];
c1[1] = measure q[1];

Note that quantum registers are combined because the indices of qubits will be mapped to physical indices by a transpiler.

@rwakizaka rwakizaka marked this pull request as draft December 11, 2025 07:44
@rwakizaka rwakizaka marked this pull request as ready for review December 11, 2025 08:03
@rwakizaka rwakizaka changed the title Output specified register names to QASM3 Output specified classical register names to QASM3 Dec 11, 2025
@doichanj doichanj merged commit 47cc0ba into Qiskit:main Jan 5, 2026
6 checks passed
@rwakizaka rwakizaka deleted the specify-register-names branch January 9, 2026 05:03
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.

2 participants