Skip to content

Add internal evolve methods by Clifford gates#15813

Open
ShellyGarion wants to merge 10 commits intoQiskit:mainfrom
ShellyGarion:more_evolve_gates
Open

Add internal evolve methods by Clifford gates#15813
ShellyGarion wants to merge 10 commits intoQiskit:mainfrom
ShellyGarion:more_evolve_gates

Conversation

@ShellyGarion
Copy link
Copy Markdown
Member

Summary

Add internal evolve methods by gate for some Clifford gates that were missing:
_evolve_sx, _evolve_sxdg, _evolve_dcx, _evolve_iswap.

Details and comments

see also: #15798 (comment)

@ShellyGarion ShellyGarion added this to the 2.5.0 milestone Mar 15, 2026
@ShellyGarion ShellyGarion requested a review from a team as a code owner March 15, 2026 14:28
@ShellyGarion ShellyGarion added mod: quantum info Related to the Quantum Info module (States & Operators) Changelog: None Do not include in the GitHub Release changelog. labels Mar 15, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@gadial gadial self-assigned this Mar 15, 2026
@ShellyGarion ShellyGarion changed the title Add internal evolve methods by gate Add internal evolve methods by Clifford gates Mar 15, 2026
op = Operator(gate)
pauli = Pauli(label)
target = op.dot(pauli).dot(op.adjoint())
value = Operator(pauli._append_circuit(qc))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we test this with public API instead of private methods? Can't we just use pauli.evolve(gate)? Same comment for the other occurrences of private methods 🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that we already have test_evolve_clifford1 (line 432) and test_evolve_clifford2 (line 496) that check the evolve method for 1 and 2 clifford gates. These tests are dedicated to check the specific internal _append_circuit method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In 0b8e957 I enhanced test_evolve_clifford_circuit that now checks the evolve method of a random clifford circuit and not only of a random clifford.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But evolve calls _append_circuit, doesn't it? I'm not sure I see the advantage of testing internal methods, which we generally avoid unless there's no other sufficient way of testing.

Copy link
Copy Markdown
Member Author

@ShellyGarion ShellyGarion Mar 27, 2026

Choose a reason for hiding this comment

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

The evolve method actually implements two internal algorithms. In case of the Clifford objects it calls _evolve_clifford (evolve by the clifford tableaux), and in case of a QuantumCircuit it calls _append_circuit

https://github.com/Qiskit/qiskit/blob/63ccd7d3c61e813d115584d9f845ed9dfa940b03/qiskit/quantum_info/operators/symplectic/base_pauli.py#L289--#L295

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also enhanced the test_evolve_clifford_circuit in 7503fa1 and 5861b60

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My point is that we should test the public interface 🙂 Private methods are subject to arbitrary change so it could mean we have to update the tests -- whereas public interfaces remain the same and the tests ensure we remain backward compatible.

There's cases where it's difficult to properly test the functions with public interfaces only, but this is not the case here since it's fairly straightforward that Gates will actually go to _append_circuit 🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As you can see from the tests, the check of the _append_circuit method is in addition to the more general evolve method. If you think it's redundant then I can remove it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah I think it would be better to remove it (not because it is redundant but because it ties the test to unstable interfaces) - thanks! 🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK, done in 4192cc6

@ShellyGarion ShellyGarion requested a review from Cryoris March 27, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: None Do not include in the GitHub Release changelog. mod: quantum info Related to the Quantum Info module (States & Operators)

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

4 participants