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

Parallel XEB: Add option to specify pairs #6787

Merged
merged 7 commits into from
Nov 8, 2024

Conversation

eliottrosenberg
Copy link
Collaborator

No description provided.

Copy link
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
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))

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

cirq-core/cirq/experiments/two_qubit_xeb.py Outdated Show resolved Hide resolved
@NoureldinYosri NoureldinYosri enabled auto-merge (squash) November 8, 2024 18:09
Copy link

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
40 checks passed
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