Skip to content

Parallel XEB: Add option to specify pairs#6787

Merged
NoureldinYosri merged 7 commits intomainfrom
u/eliottrosenberg/parallel_xeb_pairs
Nov 8, 2024
Merged

Parallel XEB: Add option to specify pairs#6787
NoureldinYosri merged 7 commits intomainfrom
u/eliottrosenberg/parallel_xeb_pairs

Conversation

@eliottrosenberg
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

LGTM%nit

if qubits is None:
raise ValueError("Couldn't determine qubits from sampler. Please specify them.")
else:
qubits_set = set()
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.

Suggested change
qubits_set = set()
qubit_set = set(itertools.chain(*pairs))

def parallel_xeb_workflow(
sampler: 'cirq.Sampler',
qubits: Optional[Sequence['cirq.GridQubit']] = None,
pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
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.

usually new arguments go to the end

Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

lets move the new argument pairs to the end of the list

graph = nx.Graph(
pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
)
if pairs is None:
Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri Nov 7, 2024

Choose a reason for hiding this comment

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

extract this logic into a method and use it here and in the other methods

def qubits_and_pairs(
    sampler: 'cirq.Sampler',
    qubits: Optional[Sequence['cirq.GridQubit']] = None,
    pairs: Optional[Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]] = None,
) -> Tuple[Sequence['cirq.GridQubit'], Sequence[tuple['cirq.GridQubit', 'cirq.GridQubit']]]:
    """Extract qubits and pairs from sampler.
    

    If qubits are not provided, then they are extracted from the pairs (if given) or the sampler.
    If pairs are not provided then all pairs of adjacent qubits are used.

    Args:
        sampler: The quantum engine or simulator to run the circuits.
        qubits: Optional list of qubits.
        pairs: Optional list of pair to use.
    
    Returns:
        - Qubits to use.
        - Pairs of qubits to use.
    
    Raises:
        ValueError: If qubits are not specified and can't be deduced from other arguments.
    """
    if qubits is None:
        if pairs is None:
            qubits = _grid_qubits_for_sampler(sampler)
            if qubits is None:
                raise ValueError("Couldn't determine qubits from sampler. Please specify them.")
        else:
            qubits_set = set(itertools.chain(*pairs))
            qubits = list(qubits_set)

    if pairs is None:
        pairs = [
            pair for pair in itertools.combinations(qubits, 2) if _manhattan_distance(*pair) == 1
        ]

    return qubits, pairs

Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

please make the qubits_and_pairs function public, otherwisenvm, LGTM

Comment thread cirq-core/cirq/experiments/two_qubit_xeb.py Outdated
@NoureldinYosri NoureldinYosri enabled auto-merge (squash) November 8, 2024 18:09
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.85%. Comparing base (2c914ce) to head (00917c0).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6787    +/-   ##
========================================
  Coverage   97.85%   97.85%            
========================================
  Files        1081     1083     +2     
  Lines       93370    93537   +167     
========================================
+ Hits        91364    91528   +164     
- Misses       2006     2009     +3     

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

@NoureldinYosri NoureldinYosri merged commit 170b20b into main Nov 8, 2024
@pavoljuhas pavoljuhas deleted the u/eliottrosenberg/parallel_xeb_pairs branch January 22, 2025 07:28
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025

Co-authored-by: Noureldin <noureldinyosri@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants