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

[Feat] Transpile.reverse for QuantumCircuit and AbstractBlock #45

Closed
wants to merge 57 commits into from

Conversation

dominikandreasseitz
Copy link
Collaborator

@dominikandreasseitz dominikandreasseitz commented Oct 9, 2023

In order to perform adjoint differentiation, we need to reverse the circuit in the backward pass.

jpmoutinho and others added 30 commits October 2, 2023 12:55
Digital decomposition, operations and Braket backend
* Add README.

* Remove useless heading.
Co-authored-by: Kaonan Micadei <[email protected]>
Co-authored-by: Vytautas Abramavicius <[email protected]>
* state preparation
* logging
* register
* execution helpers
* qubit support
* serialization
* typing
* wavefunction overlaps

Co-authored-by: Aleksander Wennersteen <[email protected]>
Co-authored-by: Mario Dagrada <[email protected]>
Co-authored-by: Vincent Elfving <[email protected]>
Co-authored-by: Dominik Seitz <[email protected]>
Co-authored-by: Joao Moutinho <[email protected]>
Co-authored-by: Vytautas Abramavicius <[email protected]>
Co-authored-by: Niklas Heim <[email protected]>
Co-authored-by: Roland Guichard <[email protected]>
* state preparation
* logging
* register
* execution helpers
* qubit support
* serialization
* typing
* wavefunction overlaps

Co-authored-by: Aleksander Wennersteen <[email protected]>
Co-authored-by: Mario Dagrada <[email protected]>
Co-authored-by: Vincent Elfving <[email protected]>
Co-authored-by: Dominik Seitz <[email protected]>
Co-authored-by: Joao Moutinho <[email protected]>
Co-authored-by: Vytautas Abramavicius <[email protected]>
Co-authored-by: Niklas Heim <[email protected]>
Co-authored-by: Roland Guichard <[email protected]>
Co-authored-by: Aleksander Wennersteen <[email protected]>
Co-authored-by: Mario Dagrada <[email protected]>
Co-authored-by: Vincent Elfving <[email protected]>
Co-authored-by: Gert-Jan Both <[email protected]>
dominikandreasseitz and others added 9 commits October 2, 2023 14:56
* Update pre-commits.

* Gather examples and notebooks tests on schedule.

* Remove obsolete files.

* Test against Python 3.9 and 3.10.
Co-authored-by: Mario Dagrada <[email protected]>
Co-authored-by: Niklas Heim <[email protected]>
Co-authored-by: Dominik Seitz <[email protected]>
Co-authored-by: Roland Guichard <[email protected]>
Co-authored-by: Joao Moutinho <[email protected]>
Co-authored-by: Vytautas Abramavicius <[email protected]>
* Docs suggestions.

* Fix typo.

* Latest changes.

* Latest changes.

* Trigger docs tests on CI.

* More files to docs.

* fix circuit drawings

* quadance to qadance

* More docs improvements.

* fix docs build

* More suggestions and run test-docs again.

* update pulser examples

* remove mkdocs-jupyter

* update pulser example

* More improvements.

---------

Co-authored-by: jpmoutinho <[email protected]>
Co-authored-by: João P. Moutinho <[email protected]>
Co-authored-by: Vytautas Abramavicius <[email protected]>
* update readme

* remove admonition

* lint

---------

Co-authored-by: Roland Guichard <[email protected]>
* Improvements to the Pulser backend documents + change defaults

* Shorter names to the workflows

* Linting

* Improvements to the docs

* Added AnalogRZ operation to the enumeration

* Go back to idealized device

---------

Co-authored-by: Roland Guichard <[email protected]>
qadence/transpile/reverse.py Outdated Show resolved Hide resolved
@nmheim
Copy link
Collaborator

nmheim commented Oct 9, 2023

Let’s add a few tests (including nested chains), then I’m good with this:)

qadence/transpile/reverse.py Outdated Show resolved Hide resolved
@dominikandreasseitz dominikandreasseitz changed the title Add transpile.reverse [Feat] Transpile.reverse for QuantumCircuit and AbstractBlock Oct 9, 2023
Copy link
Collaborator

@RolandMacDoland RolandMacDoland left a comment

Choose a reason for hiding this comment

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

Thanks @dominikandreasseitz. I am not sure what you intend to do here. Also, I am a bit worried that your reverse operation might not be allowed if non-commutative ops are in play.

qadence/transpile/reverse.py Show resolved Hide resolved

@singledispatch
def reverse(x: QuantumCircuit | AbstractBlock) -> QuantumCircuit | AbstractBlock:
"""Reverses a QuantumCircuit or AbstractBlock."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what you mean by "reverse" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what this is supposed to accomplish is just reversing a circuit in the same way that you would reverse a list. we need it (at some point) for the adjoint method

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, so basically this is taking the adjoint of a circuit ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If so, I'd rename it adjoint or reuse the current dagger methods.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Precisely, the dagger method should accomplish the same thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no it doesnt exactly, it reverses the circuit, yes, but it also renames all the parameters to "-{parameter_name}" which its not what we want. we need the same parameter names to compute the gradients in the backward pass of the adjoint method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lets move this to #78

qadence/transpile/reverse.py Show resolved Hide resolved
@madagra
Copy link
Collaborator

madagra commented Oct 9, 2023

@dominikandreasseitz please add a small description to the MR. If there is not corresponding issue, it is better to always add it as a best practice.

@dominikandreasseitz
Copy link
Collaborator Author

moving to #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-dev feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants