Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow QuantumCircuit construction with zero qubit or clbit count #6800

Merged
merged 13 commits into from
Aug 22, 2021

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Jul 25, 2021

Summary

This PR allows construction of circuits with zero registers (either quantum or classical). The construction of these circuits is convenient with algorithmically constructing circuits with varying numbers of registers.

This is a variation on #6506. For circuits with zero qubits no quantum registers are created.

from qiskit.circuit import QuantumCircuit
for q in range(0,2):
    for c in range(0,2):
        circ = QuantumCircuit(q,c)
        print(f'QuantumCircuit({q},{c}): {circ.qregs} {circ.cregs}') 

circ = QuantumCircuit(0)
print(f'QuantumCircuit(0): {circ.qregs} {circ.cregs}') 

circ = QuantumCircuit(0)
QuantumCircuit(0,0): [] []
QuantumCircuit(0,1): [] [ClassicalRegister(1, 'c')]
QuantumCircuit(1,0): [QuantumRegister(1, 'q')] []
QuantumCircuit(1,1): [QuantumRegister(1, 'q')] [ClassicalRegister(1, 'c')]
QuantumCircuit(0): [] []

Details and comments

Variation is based on comments from #6506

@kdk

@eendebakpt eendebakpt requested a review from a team as a code owner July 25, 2021 20:42
@eendebakpt eendebakpt changed the title [WIP] Allow quantumcircuit construction with zero classical registers (2) Allow quantumcircuit construction with zero classical registers (2) Jul 26, 2021
@kdk kdk changed the title Allow quantumcircuit construction with zero classical registers (2) Allow QuantumCircuit construction with zero qubit or clbit count Aug 20, 2021
Copy link
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @eendebakpt , this looks good!

@kdk kdk added automerge Changelog: API Change Include in the "Changed" section of the changelog labels Aug 20, 2021
@kdk kdk added this to the 0.19 milestone Aug 20, 2021
@mergify mergify bot merged commit 1e27e83 into Qiskit:main Aug 22, 2021
@peendebak peendebak deleted the fix/quantumcircuit_construction2 branch August 22, 2021 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants