Skip to content

Conversation

@DmitryVasilevsky
Copy link
Contributor

This PR implements the old suggestion by @msoeken and resolves the last remaining item in the issue #1104.

The suggestion was "Instead of performing Controlled X apply an AND chain. I think you added such an operation for the PhaseUp..."

Also introduces a test for controlled version of preparation.

Closes #1104

@github-actions
Copy link

Change in memory usage detected by benchmark.

Memory Report for eed7a1f

Test This Branch On Main Difference
compile core + standard lib 24735222 bytes 24729454 bytes 5768 bytes

@swernli
Copy link
Collaborator

swernli commented Oct 20, 2025

What impact does this have on the resource counts? The two approaches look almost the same in terms of how they apply AND under the covers, just one recursively while the other is iterative, so I'm not sure why one would be preferred over the other.

within {
Controlled X(controlRegister, target);
// Reduce circuit complexity by using aux qubits.
Controlled ApplyAsSinglyControlled(controlRegister, (X, target));
Copy link
Member

Choose a reason for hiding this comment

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

One can still save a factor of 2x by only doing the forward direction of the multi-controlled X gate (chain of computing ANDs) and then the backward direction (chain of uncomputing ANDs) afterwards. However, this will require to allocate the helper qubits in this operation.

For a 3-qubit controlRegister the trace would be as follows:

use helper = Qubit[1];

And(controlRegister[0], controlRegister[1], helper[0]);
And(controlRegister[1], helper[0], target);

ApproximatelyMultiplexZ(tolerance, coefficients1, control, target);

Adjoint And(controlRegister[1], helper[0], target);
Adjoint And(controlRegister[0], controlRegister[1], helper[0]);

@msoeken
Copy link
Member

msoeken commented Oct 21, 2025

What impact does this have on the resource counts? The two approaches look almost the same in terms of how they apply AND under the covers, just one recursively while the other is iterative, so I'm not sure why one would be preferred over the other.

Maybe it's worth to add tests for logical counts to the test suite for some operations like these ones. We can use the LogicalCounst backend in Rust or the logical_counts function in Python, depending on where the tests live.

@DmitryVasilevsky DmitryVasilevsky marked this pull request as draft October 31, 2025 18:47
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.

State preparation could be better

4 participants