Skip to content

Conversation

NoureldinYosri
Copy link
Collaborator

@NoureldinYosri NoureldinYosri commented Jan 10, 2025

This is a new implemenation of parallel XEB that doesn't rely on legacy code. This module reimplements almost all of the what is needed to run parallel XEB. The reason for a completly new implementation is that the old implementation (also written by me) relied on old code that don't support the new use case of running XEB on circuits that depenend on the qubit pair and the effort needed to update the old code is more than the effort needed to write a new implementation.

>> import cirq
>> import cirq.experiments.benchmarking.parallel_xeb as xeb
>> sampler = cirq.DensityMatrixSimulator(
    seed=0, noise=cirq.ConstantQubitNoiseModel(cirq.depolarize(1e-2))
)
>> qubits = cirq.q(0, 0), cirq.q(0, 1), cirq.q(0, 2)
>> parameters = xeb.XEBParameters(
    n_repetitions = 10**4,
    n_combinations = 20,
    n_circuits = 30,
    cycle_depths = (5, 25, 50, 100, 200, 300),
)
>> circ = cirq.Circuit(cirq.X(cirq.q(0)), cirq.Y(cirq.q(1)), cirq.CZ(cirq.q(1), cirq.q(0)))
>> xeb.parallel_two_qubit_xeb(sampler, qubits=qubits, target={(cirq.q(0, 0), cirq.q(0, 1)): circ})
TwoQubitXEBResult(fidelities=                           a  layer_fid                cycle_depths  \
pair                                                                  
(q(0, 0), q(0, 1))  0.948672   0.958812  [5, 25, 50, 100, 200, 300]   

                                                           fidelities  \
pair                                                                    
(q(0, 0), q(0, 1))  [0.7693233439521296, 0.3291275172915138, 0.118...   

                       a_std  layer_fid_std  
pair                                         
(q(0, 0), q(0, 1))  0.007211       0.000565  )

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.67%. Comparing base (8c5753d) to head (b24f317).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6940    +/-   ##
========================================
  Coverage   98.66%   98.67%            
========================================
  Files        1106     1109     +3     
  Lines       96448    96826   +378     
========================================
+ Hits        95165    95542   +377     
- Misses       1283     1284     +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

pool: Optional['multiprocessing.pool.Pool'] = None,
batch_size: int = 9,
tags: Sequence[Any] = (),
entangling_circuit_or_op: Optional[Union['cirq.AbstractCircuit', 'cirq.Operation']] = None,
Copy link
Collaborator

@eliottrosenberg eliottrosenberg Jan 14, 2025

Choose a reason for hiding this comment

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

Actually, in order to do parallel XEB, we will want to be able to input something like a set of circuits (that each act on two qubits) or a dictionary from pairs to circuits because, for example, we may have different z-phase corrections on different pairs of qubits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reimplemented parallel XEB to support this use case. ptal

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, Nour! I will take a look soon.

@CirqBot CirqBot added the size: M 50< lines changed <250 label Jan 18, 2025
@NoureldinYosri NoureldinYosri marked this pull request as draft February 5, 2025 05:41
@NoureldinYosri NoureldinYosri changed the title update parallel XEB methods to support circuits instead of single gates Create a new implementation of parallel XEB and its dependencies Feb 5, 2025
@NoureldinYosri NoureldinYosri changed the title Create a new implementation of parallel XEB and its dependencies Create a new implementation of parallel XEB and its methods Feb 5, 2025
Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

I tried using it and got an error (colab). Also, maybe we can call the folder benchmarking instead of error_mitigation.

Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

I tried it again inputting a dictionary and am still getting an error when I do result.pauli_error() (colab)

@github-actions github-actions bot added size: XL lines changed >1000 and removed size: M 50< lines changed <250 labels May 4, 2025
@NoureldinYosri NoureldinYosri requested a review from pavoljuhas May 4, 2025 21:30
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

LGTM. Please fix type annotations for the new return value.

@NoureldinYosri NoureldinYosri enabled auto-merge May 5, 2025 17:58
@NoureldinYosri NoureldinYosri added this pull request to the merge queue May 5, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 5, 2025
* update parallel XEB methods to support circuits instead of single gates

* map qubits

* nit

* type

* validate input

* nit

* nit

* Reimplement parallel XEB and restore old files

* nit

* add __init__.py

* format

* fix issues

* fix indexing issue

* fix pair dropping issue

* remove debug statements

* checkpoint

* add docstring and tests

* fix mypy

* coverage

* coverage

* coverage

* address comments

* format

* change fidelity estimator from probability ratio model to cross entropy model

* make test robust to noise

* nit

* Fix spelling typos

* Address type check

* Use unquoted type annotations in new source files

* address comments

* fix mypy

---------

Co-authored-by: Michael Hucka <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
@NoureldinYosri NoureldinYosri removed this pull request from the merge queue due to a manual request May 5, 2025
@NoureldinYosri NoureldinYosri enabled auto-merge May 5, 2025 21:22
@NoureldinYosri NoureldinYosri added this pull request to the merge queue May 5, 2025
Merged via the queue into quantumlib:main with commit 575552a May 5, 2025
39 checks passed
@NoureldinYosri NoureldinYosri deleted the circuit_xeb branch May 5, 2025 21:59
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…ib#6940)

* update parallel XEB methods to support circuits instead of single gates

* map qubits

* nit

* type

* validate input

* nit

* nit

* Reimplement parallel XEB and restore old files

* nit

* add __init__.py

* format

* fix issues

* fix indexing issue

* fix pair dropping issue

* remove debug statements

* checkpoint

* add docstring and tests

* fix mypy

* coverage

* coverage

* coverage

* address comments

* format

* change fidelity estimator from probability ratio model to cross entropy model

* make test robust to noise

* nit

* Fix spelling typos

* Address type check

* Use unquoted type annotations in new source files

* address comments

* fix mypy

* set seed in all tests

---------

Co-authored-by: Michael Hucka <[email protected]>
Co-authored-by: Pavol Juhas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/after-1.5 Leave for after the Cirq 1.5 release size: XL lines changed >1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants