-
Notifications
You must be signed in to change notification settings - Fork 157
Add optional prune_classical_qubits setting for circuit generation
#2802
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
base: main
Are you sure you want to change the base?
Conversation
|
I'm a bit uneasy about this feature as it is. The trimmed circuit is not equivalent to the original and it may be confusing. For example, I can create this circuit: operation Foo() : Result {
use qs = Qubit[2];
X(qs[0]);
CNOT(qs[0], qs[1]);
H(qs[1]);
Ry(Std.Math.PI() / 2.0, qs[1]);
X(qs[0]);
MResetZ(qs[1])
}In this circuit the first qubit is trimmable, but the second is not. We can compare original and resulting circuits. |
trim setting for circuit generationprune_classical_qubits setting for circuit generation
920cd6c to
260bf32
Compare
@DmitryVasilevsky, I believe the new logic handles this appopriately. Using your same sample code, the output now looks the way you were hoping, keeping the circuit equivalent: I'll need more tests to ensure this across different inputs though! |
This change adds a parameter to Q# and OpenQASM circuit generation called `trim` that will generate a simplified circuit diagram where qubits that are unused or purely classical (never enter superposition) are removed. This can be handy for places where the program comes from generated logic that may use more qubits than strictly needed. This is purely for visualizing the simplified circuit and does not perform any kind of execution optimization.
…, still need tests
260bf32 to
88b2c87
Compare
|
@DmitryVasilevsky @minestarks This is now ready for review with the updated behavior based on your feedback. No rush to get this in soon though. |



This change adds a parameter to Q# and OpenQASM circuit generation called
prune_classical_qubitsthat will generate a simplified circuit diagram where qubits that are unused or purely classical (never enter superposition) are removed. This can be handy for places where the program comes from generated logic that may use more qubits than strictly needed. This is purely for visualizing the simplified circuit and does not perform any kind of execution optimization.So a program like this that has nine qubits but doesn't really use all of them:

will by default show the full circuit as it does today:

but with

prune_classical_qubits = Truewill remove the purely classical q1, q2, q4, q5, and q8: