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

Change Sampler methods to return Sequence instead of List #4807

Merged
merged 3 commits into from
Jan 7, 2022

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Jan 6, 2022

Sequence is a covariant type (Sequence[A] is a subclass of Sequence[B] when A is a subclass of B) while List, because it is mutable, is invariant (List[A] is not a subclass of List[B] even if A is a subclass of B). Returning Sequence[cirq.Result] thus allows returning subtypes of cirq.Result, while List[cirq.Result] does not.

We change cirq.Sampler methods run_sweep and run_batch to return Sequence[cirq.Result] and Sequence[Sequence[cirq.Result]], respectively, which makes it possible to return result subtypes if desired, as needed in #4806.

Sequence is a covariant type (Sequence[A] is a subclass of Sequence[B]
when A is a subclass of B) while List is invariant (List[A] is not a
subclass of List[B] even in A is a subclass of B). Returning
Sequence[cirq.Result] thus allows returning subtypes of cirq.Result,
while List[cirq.Result] does not.
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jan 6, 2022
@maffoo maffoo merged commit 979a443 into master Jan 7, 2022
@maffoo maffoo deleted the u/maffoo/results branch January 7, 2022 00:09
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
…#4807)

Sequence is a covariant type (Sequence[A] is a subclass of Sequence[B]
when A is a subclass of B) while List is invariant (List[A] is not a
subclass of List[B] even in A is a subclass of B). Returning
Sequence[cirq.Result] thus allows returning subtypes of cirq.Result,
while List[cirq.Result] does not.

Review: @viathor
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…#4807)

Sequence is a covariant type (Sequence[A] is a subclass of Sequence[B]
when A is a subclass of B) while List is invariant (List[A] is not a
subclass of List[B] even in A is a subclass of B). Returning
Sequence[cirq.Result] thus allows returning subtypes of cirq.Result,
while List[cirq.Result] does not.

Review: @viathor
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…#4807)

Sequence is a covariant type (Sequence[A] is a subclass of Sequence[B]
when A is a subclass of B) while List is invariant (List[A] is not a
subclass of List[B] even in A is a subclass of B). Returning
Sequence[cirq.Result] thus allows returning subtypes of cirq.Result,
while List[cirq.Result] does not.

Review: @viathor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants