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

spin_echoes.ipynb references a removed optimizer #6807

Open
pavoljuhas opened this issue Nov 21, 2024 · 1 comment
Open

spin_echoes.ipynb references a removed optimizer #6807

pavoljuhas opened this issue Nov 21, 2024 · 1 comment
Labels
area/docs area/tutorials good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/docs Documentation related problems, ideas, requests kind/health For CI/testing/release process/refactoring/technical debt items triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@pavoljuhas
Copy link
Collaborator

Description of the issue

docs/tutorials/google/spin_echoes.ipynb references cirq.MergeInteractionsToSqrtIswap which was removed in #5727.

Solution

Replace with a working transformer in the notebook, make sure this is rendered on cirq webpage.
Also search for and fix other invalid cirq.Something references in the repository.

Cirq version

1.5.0.dev at 2991e80

@pavoljuhas pavoljuhas added kind/health For CI/testing/release process/refactoring/technical debt items good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" area/tutorials labels Nov 21, 2024
@NoureldinYosri NoureldinYosri added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Dec 11, 2024
@mhucka mhucka added kind/docs Documentation related problems, ideas, requests triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on area/docs and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Dec 11, 2024
@ayshiff
Copy link

ayshiff commented Dec 29, 2024

Hello,

I'm interested in working on this issue if it's still available.

I've already started playing around with the notebook, cleaning it up and regenerating the output by replacing the old cirq.MergeInteractionsToSqrtIswap references with the cirq.optimize_for_target_gateset function transforming the operations to use the cirq.SqrtIswapTargetGateset.

I've been running the notebook locally using a Weber QVM, but I've not been able to notice a negligible difference in the final diagram survival probability between the optimized and unoptimized circuits. I'm not sure if running the tutorial on real Weber hardware would result in a more significant difference.

I want to make sure I am doing things correctly.

Any guidance would be really helpful. Thanks

EDIT 2: I think I just need to tweak how create_benchmark_circuit optimizes the circuit (especially with merge_k_qubit_unitaries as I thought it was already called in the transformer). I'll take a look at that.

EDIT 1:

Here is the result diagram for reference:

Screenshot 2024-12-29 at 18 45 50

Here is also how I transformed the operations to use the cirq.SqrtIswapTargetGateset (in the non-benchmark section):

qubits = cirq.GridQubit.rect(2, 3)  # [cirq.GridQubit(x, y) for (x, y) in [(3, 2), (4, 2), (4, 1), (5, 1), (6, 1), (6, 2), (5, 2)]]
circuit = create_benchmark_circuit(qubits, twoq_gate=cirq.ISWAP, cycles=3, seed=1)

optimized_circuit = cirq.optimize_for_target_gateset(
    circuit, context=cirq.TransformerContext(deep=True), gateset=cirq.SqrtIswapTargetGateset(required_sqrt_iswap_count=2)
)

And here's the output I got:

Original circuit:
Moments: 51
Gate count: 52

(0, 0): ───X───iSwap────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────iSwap──────────────────────────────────────────────────────────M('z')───
               │                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        │
(0, 1): ───────iSwap───PhX(0.25)^0.5──────────────────────────────────────────────────────────────────────PhX(-0.75)^0.5─────────────────────────────────────────────────────────────────iSwap───PhX(0.75)^0.5──────────────────────────────────────────────────────────────iSwap───────────PhX(0.25)^0.5──────────────────────────────────────────────────────────────PhX(0.25)^-0.5──────────────────────────────────────────────────────────────────iSwap─────────────────PhX(0.75)^-0.5──────────────────────────────────────────────────────────────────iSwap──────PhX(-0.75)^-0.5────────────────────────────────────────────────────────────────────────────────PhX(0.25)^-0.5───iSwap^-1────────────────────────────────────────────────────────────────
                                                                                                                                                                                         │                                                                                  │                                                                                                                                                                          │                                                                                                     │
(0, 2): ───────────────────────────────PhX(-0.25)^0.5─────────────────────────────────────────────iSwap────────────────────PhX(0.25)^0.5─────────────────────────────────────────────────┼───────────────────────PhX(0)^0.5─────────────────────────────────────────────────iSwap───────────────────────────PhX(-0.5)^0.5───────────────────────────────────────────────────────────────PhX(-0.5)^-0.5─────────────────────────────────────────────────iSwap^-1───────────────────────────────PhX(0)^-0.5────────────────────────────────────────────────────┼────────────────────────────PhX(0.25)^-0.5────────────────────────────────────────────────────iSwap───────────────────────PhX(-0.25)^-0.5─────────────────────────────────────────────────────────
                                                                                                  │                                                                                      │                                                                                                                                                                                                                                                                                                                                                                   │                                                                                              │
(1, 0): ────────────────────────────────────────────────PhX(0)^0.5────────────────────────────────┼────────────────────────────────────────PhX(0.75)^0.5─────────────────────────────────┼────────────────────────────────────PhX(0.5)^0.5──────────────────────────────────────────iSwap───────────────────────────────────PhX(0)^0.5───────────────────────────────────────────────────────────────────PhX(0)^-0.5──────────────────────────────────────────────iSwap─────────────────────────────────────PhX(0.5)^-0.5────────────────────────────────────┼─────────────────────────────────────────────PhX(0.75)^-0.5───────────────────────────────────┼─────────────────────────────────────────────PhX(0)^-0.5───────────────────────────────────────────
                                                                                                  │                                                                                      │                                                                                          │                                                                                                                                                                             │                                                                                          │                                                                                              │
(1, 1): ─────────────────────────────────────────────────────────────PhX(1)^0.5───────────────────┼────────────────────────────────────────────────────────PhX(-0.75)^0.5────────────────iSwap───────────────────────────────────────────────PhX(-0.5)^0.5──────────────────────────iSwap────────────────────────────────────────────────PhX(-0.25)^0.5────────────────────────────────────────────────────────────────PhX(-0.25)^-0.5────────────────────────────iSwap^-1──────────────────────────────────────────────────PhX(-0.5)^-0.5───────────────────iSwap^-1───────────────────────────────────────────────────────PhX(-0.75)^-0.5─────────────────┼───────────────────────────────────────────────────────────PhX(1)^-0.5─────────────────────────────
                                                                                                  │                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         │
(1, 2): ──────────────────────────────────────────────────────────────────────────PhX(0.75)^0.5───iSwap─────────────────────────────────────────────────────────────────────PhX(0)^0.5───────────────────────────────────────────────────────────────────────PhX(0.5)^0.5─────────────────────────────────────────────────────────────────────────────────PhX(0)^0.5─────────────────────────────────────────────────────────────────────PhX(0)^-0.5─────────────────────────────────────────────────────────────────────────────────────────PhX(0.5)^-0.5────────────────────────────────────────────────────────────────────────────────────PhX(0)^-0.5───iSwap^-1──────────────────────────────────────────────────────────────────PhX(0.75)^-0.5────────────


Circuit with optimization:
Moments: 28
Gate count: 45

(0, 0): ───PhXZ(a=0.25,x=1,z=0)───iSwap───────iSwap───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────PhXZ(a=2.22e-16,x=0,z=0.5)───iSwap───────iSwap───────PhXZ(a=-0.5,x=0,z=-1)───M('z')───
                                  │           │                                                                                                                                                                                                                                                                                                                                                                                                                                            │           │
(0, 1): ──────────────────────────iSwap^0.5───iSwap^0.5───PhXZ(a=0.841,x=0,z=-0.5)────────────────────────────PhXZ(a=2.22e-16,x=0,z=0.5)────iSwap───────iSwap───────PhXZ(a=-0.44,x=0.252,z=0.436)────────iSwap───────PhXZ(a=-0.5,x=0,z=-1)───iSwap───────PhXZ(a=-0.00417,x=0.252,z=0.564)───────────────────────────────────────────────────PhXZ(a=2.22e-16,x=0,z=0.5)───────iSwap───────iSwap───────PhXZ(a=-0.349,x=2.22e-16,z=-1)────────────────────────────────────────────────────────iSwap^0.5───iSwap^0.5───PhXZ(a=0,x=0,z=0.5)──────────────
                                                                                                                                            │           │                                                │                                   │                                                                                                                               │           │
(0, 2): ──────────────────────────────────────────────────PhXZ(a=-0.25,x=0.5,z=0.5)───iSwap───────iSwap───────PhXZ(a=-0.25,x=0.75,z=0.75)───┼───────────┼───────────PhXZ(a=0.00584,x=0.766,z=-0.00584)───iSwap^0.5───────────────────────────iSwap^0.5───PhXZ(a=-0.309,x=0.328,z=0.345)──────────────────────────────────────────────────────────────────────────────────────┼───────────┼───────────PhXZ(a=2.22e-16,x=0,z=0.5)───────iSwap───────iSwap───────PhXZ(a=-0.25,x=0.5,z=-1)──────────────────────────────────────────────────────────────
                                                                                      │           │                                         │           │                                                                                                                                                                                                                    │           │                                            │           │
(1, 0): ──────────────────────────────────────────────────────────────────────────────┼───────────┼─────────────────────────────────────────┼───────────┼────────────────────────────────────────────────────────────────────────────────────────────────PhXZ(a=0.00542,x=0.537,z=0.571)────iSwap───────PhXZ(a=-0.5,x=0,z=-1)───iSwap───────PhXZ(a=0.577,x=0.537,z=0.429)────┼───────────┼────────────────────────────────────────────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                      │           │                                         │           │                                                                                                                                   │                                   │                                            │           │                                            │           │
(1, 1): ──────────────────────────────────────────────────────────────────────────────┼───────────┼───────────PhXZ(a=-0.5,x=0.75,z=-0.75)───iSwap^0.5───iSwap^0.5───PhXZ(a=0,x=0.5,z=-0.5)───────────────────────────────────────────────────────────────PhXZ(a=0.485,x=0.461,z=-0.485)─────iSwap^0.5───────────────────────────iSwap^0.5───PhXZ(a=0.116,x=0.0417,z=0.499)───iSwap^0.5───iSwap^0.5───PhXZ(a=-0.75,x=0.75,z=-0.75)─────┼───────────┼─────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                      │           │                                                                                                                                                                                                                                                                                                                                   │           │
(1, 2): ──────────────────────────────────────────────────PhXZ(a=-0.25,x=-0.5,z=0)────iSwap^0.5───iSwap^0.5───PhXZ(a=0.447,x=0,z=-0.5)────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────iSwap^0.5───iSwap^0.5───PhXZ(a=-0.75,x=0.5,z=0.5)─────────────────────────────────────────────────────────────

Circuits are equivalent (up to global phase).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs area/tutorials good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/docs Documentation related problems, ideas, requests kind/health For CI/testing/release process/refactoring/technical debt items 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

4 participants