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

Organization (and deprecation) of cirq-core/optimizers in cirq-core/transformers #4722

Closed
24 tasks done
tanujkhattar opened this issue Dec 3, 2021 · 7 comments
Closed
24 tasks done
Assignees
Labels
area/transformers help wanted kind/design-issue A conversation around design triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@tanujkhattar
Copy link
Collaborator

tanujkhattar commented Dec 3, 2021

Background

Currently, all optimizers in cirq are present in a single directory -- cirq-core/cirq/optimizers/*. It contains not only transformers (which transform/optimize circuits) but also utility methods like analytical decompositions of matrices into target operations.
Also, after #4708 and #4692; almost all existing optimizers would need to be re-implemented to

Proposal

The proposal is to

  1. Create a new cirq/transformers/
  2. Move decomposition utilities from cirq/optimizers to sub directories under cirq/transformers/
  3. Deprecate the existing transformers in cirq/optimizers in favor of new implementations using the moment preserving primitives and following the new non-mutating API, which would be added at top-level in cirq/transformers/.

cirq-core/cirq/transformers/heuristic_decompositions/*

Note: Heuristic compilation is an active area of research and is an important primitive for compensating for actual gate angles calibrated via techniques like Floquet / XEB calibration. We can expect more primitives to get added here in future.

cirq-core/cirq/transformers/analytical_decompositions/*

  • clifford_decomposition.py
  • controlled_gate_decomposition.py
  • cphase_to_fsim.py
  • decompositions.py --> single_qubit_decompositions.py
  • three_qubit_decomposition.py
  • two_qubit_decompositions.py --> two_qubit_to_cz.py
  • two_qubit_state_preparation.py
  • two_qubit_to_fsim.py
  • two_qubit_to_sqrt_iswap.py

Newer versions of the following existing transformers in cirq-core/cirq/optimizers/* will get added in cirq-core/cirq/transformers/*

  • align_left.py
  • align_right.py
  • convert_to_cz_and_single_gates.py
  • drop_empty_moments.py
  • drop_negligible.py
  • eject_phased_paulis.py
  • eject_z.py
  • expand_composite.py
  • merge_interactions.py
  • merge_interactions_to_sqrt_iswap.py
  • merge_single_qubit_gates.py
  • stratify.py
  • synchronize_terminal_measurements.py
  • transformer_primitives.py

Deprecation Plan

  • For analytical decomposers, the existing files will simply get moved from cirq/optimizers/* to cirq/transformers/analytical_decompositions. Existing methods will go through a deprecation cycle and the change should not impact usages of the form cirq.<method>.
  • For existing transformers -- it would be a large breaking change to deprecate all existing transformers in the favour of newer moment-preserving non mutating versions but this is unavoidable and need to happen as part of the larger effort on redesigning transformers. The existing transformers can be left around for a few versions for the user code to get updated since the new versions would be implemented independently of existing versions.

cc @MichaelBroughton @dstrain115 @dabacon Thoughts?
Part of roadmap #3238

@tanujkhattar tanujkhattar added kind/design-issue A conversation around design area/transformers triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Dec 3, 2021
@MichaelBroughton
Copy link
Collaborator

I like the looks of this plan.

Create a new cirq/transformers/
Move decomposition utilities from cirq/optimizers to sub directories under cirq/transformers/
Deprecate the existing transformers in cirq/optimizers in favor of new implementations using the moment preserving primitives and following the new non-mutating API, which would be added at top-level in cirq/transformers/.

Where possible, I would be in favor of doing this one module at a time and not all at once so multiple people can work on this at once and also take the opportunity for the rewrite/cleanup of their module one module at a time.

@MichaelBroughton MichaelBroughton added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on help wanted and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Dec 8, 2021
@dstrain115
Copy link
Collaborator

This is fine with me, but we should announce this broadly. We already mentioned at a cirq cync, but it might be worth an email to cirq-announce. We could maybe combine this with a forward-looking "What's changing in cirq 1.0" email to all of cirq-announce that explains all the changes we are planning to do.

@tanujkhattar tanujkhattar changed the title Organization of cirq-core/optimizers Organization (and deprecation) of cirq-core/optimizers in cirq-core/transformers Dec 13, 2021
CirqBot pushed a commit that referenced this issue Dec 23, 2021
…lytical_decompositions/two_qubit_state_preparation.py` (#4762)

Part of #4722

This is safe to do without going through a deprecation cycle because `optimizers/two_qubit_state_preparation.py ` was recently introduced (#4707) in the current dev version and hasn't been released yet.
CirqBot pushed a commit that referenced this issue Jan 4, 2022
…rq/transformers/analytical_decompositions/` (#4785)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- clifford_decomposition.py
- controlled_gate_decomposition.py
- cphase_to_fsim.py


Part of #4722
CirqBot pushed a commit that referenced this issue Jan 5, 2022
…positions/single_qubit_decompositions.py` (#4799)

Moves the following file from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

 - decompositions.py --> single_qubit_decompositions.py

Part of #4722
CirqBot pushed a commit that referenced this issue Jan 7, 2022
…rs/analytical_decompositions` (#4809)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- two_qubit_decompositions.py --> two_qubit_to_cz.py
- two_qubit_to_fsim.py
- two_qubit_to_sqrt_iswap.py
- three_qubit_decomposition.py

Part of #4722
CirqBot pushed a commit that referenced this issue Jan 7, 2022
…ers/*` (#4813)

After the recent migration of decompositions from `optimizers/*` to `transformers/analytical_decompositions/*`, the following user code breaks despite deprecating the moved submodules. 

```python
from cirq import optimizers
from cirq.optimizers import two_qubit_decompositions
_ = two_qubit_decompositions.two_qubit_matrix_to_operations(mat) # This is deprecated correctly and will emit a deprecation warning but work as expected.
_ = optimizers.two_qubit_matrix_to_operations(mat) # This would currently break since the optimizers module is neither deprecated nor has these top-level objects available
```

This PR adds a fix to temporarily unbreak the above user code by importing top-level objects from `transformers/analytical_decompositions/*` to `optimizers/*`. Once all files from `optimizers/*` have been moved to `transformers/`, we will deprecate the `optimizers/` module, and then this hack can be reverted and the correct deprecation warnings will be emitted when using `optimizers.two_qubit_matrix_to_operations` (and other top-level objects). 

Part of #4722
@pavoljuhas
Copy link
Collaborator

Picking up expand_composite.py. Please let me know if someone already works on it.

@tanujkhattar tanujkhattar self-assigned this Jan 14, 2022
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this issue Jan 22, 2022
…lytical_decompositions/two_qubit_state_preparation.py` (quantumlib#4762)

Part of quantumlib#4722

This is safe to do without going through a deprecation cycle because `optimizers/two_qubit_state_preparation.py ` was recently introduced (quantumlib#4707) in the current dev version and hasn't been released yet.
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this issue Jan 22, 2022
…rq/transformers/analytical_decompositions/` (quantumlib#4785)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- clifford_decomposition.py
- controlled_gate_decomposition.py
- cphase_to_fsim.py


Part of quantumlib#4722
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this issue Jan 22, 2022
…positions/single_qubit_decompositions.py` (quantumlib#4799)

Moves the following file from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

 - decompositions.py --> single_qubit_decompositions.py

Part of quantumlib#4722
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this issue Jan 22, 2022
…rs/analytical_decompositions` (quantumlib#4809)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- two_qubit_decompositions.py --> two_qubit_to_cz.py
- two_qubit_to_fsim.py
- two_qubit_to_sqrt_iswap.py
- three_qubit_decomposition.py

Part of quantumlib#4722
@anonymousr007
Copy link
Contributor

Hi all, I would like to help with this issue, Can anyone please tell me further details?

@vtomole
Copy link
Collaborator

vtomole commented Mar 12, 2022

From the check list, it seems like the only thing left to close this is #4362, but @Ashalynd is already working on it.

@tanujkhattar
Copy link
Collaborator Author

The task which is still open is about adding a new transformer and not migrating any existing transformer, so I'm going to remove the task from the list and the issue will be tracked independently.

This particular issue is about migration of all existing optimizers, which has been completed and I'll therefore go ahead and close the issue.

rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
…lytical_decompositions/two_qubit_state_preparation.py` (quantumlib#4762)

Part of quantumlib#4722

This is safe to do without going through a deprecation cycle because `optimizers/two_qubit_state_preparation.py ` was recently introduced (quantumlib#4707) in the current dev version and hasn't been released yet.
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
…rq/transformers/analytical_decompositions/` (quantumlib#4785)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- clifford_decomposition.py
- controlled_gate_decomposition.py
- cphase_to_fsim.py


Part of quantumlib#4722
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
…positions/single_qubit_decompositions.py` (quantumlib#4799)

Moves the following file from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

 - decompositions.py --> single_qubit_decompositions.py

Part of quantumlib#4722
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
…rs/analytical_decompositions` (quantumlib#4809)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- two_qubit_decompositions.py --> two_qubit_to_cz.py
- two_qubit_to_fsim.py
- two_qubit_to_sqrt_iswap.py
- three_qubit_decomposition.py

Part of quantumlib#4722
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
…ers/*` (quantumlib#4813)

After the recent migration of decompositions from `optimizers/*` to `transformers/analytical_decompositions/*`, the following user code breaks despite deprecating the moved submodules. 

```python
from cirq import optimizers
from cirq.optimizers import two_qubit_decompositions
_ = two_qubit_decompositions.two_qubit_matrix_to_operations(mat) # This is deprecated correctly and will emit a deprecation warning but work as expected.
_ = optimizers.two_qubit_matrix_to_operations(mat) # This would currently break since the optimizers module is neither deprecated nor has these top-level objects available
```

This PR adds a fix to temporarily unbreak the above user code by importing top-level objects from `transformers/analytical_decompositions/*` to `optimizers/*`. Once all files from `optimizers/*` have been moved to `transformers/`, we will deprecate the `optimizers/` module, and then this hack can be reverted and the correct deprecation warnings will be emitted when using `optimizers.two_qubit_matrix_to_operations` (and other top-level objects). 

Part of quantumlib#4722
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
…ronizeTerminalMeasurements` (quantumlib#4911)

- Part of quantumlib#4722
- Follows the new Transformer API quantumlib#4483
- Supports no compile tags NoCompile Tag for optimizers quantumlib#4253
- Fixes quantumlib#4907
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…lytical_decompositions/two_qubit_state_preparation.py` (quantumlib#4762)

Part of quantumlib#4722

This is safe to do without going through a deprecation cycle because `optimizers/two_qubit_state_preparation.py ` was recently introduced (quantumlib#4707) in the current dev version and hasn't been released yet.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…rq/transformers/analytical_decompositions/` (quantumlib#4785)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- clifford_decomposition.py
- controlled_gate_decomposition.py
- cphase_to_fsim.py


Part of quantumlib#4722
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…positions/single_qubit_decompositions.py` (quantumlib#4799)

Moves the following file from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

 - decompositions.py --> single_qubit_decompositions.py

Part of quantumlib#4722
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…rs/analytical_decompositions` (quantumlib#4809)

Moves the following files from `cirq/optimizers/` to `cirq/transformers/analytical_decompositions/` using `deprecated_submodule`:

- two_qubit_decompositions.py --> two_qubit_to_cz.py
- two_qubit_to_fsim.py
- two_qubit_to_sqrt_iswap.py
- three_qubit_decomposition.py

Part of quantumlib#4722
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…ers/*` (quantumlib#4813)

After the recent migration of decompositions from `optimizers/*` to `transformers/analytical_decompositions/*`, the following user code breaks despite deprecating the moved submodules. 

```python
from cirq import optimizers
from cirq.optimizers import two_qubit_decompositions
_ = two_qubit_decompositions.two_qubit_matrix_to_operations(mat) # This is deprecated correctly and will emit a deprecation warning but work as expected.
_ = optimizers.two_qubit_matrix_to_operations(mat) # This would currently break since the optimizers module is neither deprecated nor has these top-level objects available
```

This PR adds a fix to temporarily unbreak the above user code by importing top-level objects from `transformers/analytical_decompositions/*` to `optimizers/*`. Once all files from `optimizers/*` have been moved to `transformers/`, we will deprecate the `optimizers/` module, and then this hack can be reverted and the correct deprecation warnings will be emitted when using `optimizers.two_qubit_matrix_to_operations` (and other top-level objects). 

Part of quantumlib#4722
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
…ronizeTerminalMeasurements` (quantumlib#4911)

- Part of quantumlib#4722
- Follows the new Transformer API quantumlib#4483
- Supports no compile tags NoCompile Tag for optimizers quantumlib#4253
- Fixes quantumlib#4907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/transformers help wanted kind/design-issue A conversation around design triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

No branches or pull requests

6 participants