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

Speed up some over parameterized tests #5606

Merged
merged 10 commits into from
Jun 25, 2022
Merged

Conversation

dabacon
Copy link
Collaborator

@dabacon dabacon commented Jun 24, 2022

No description provided.

@dabacon dabacon requested review from wcourtney, a team, vtomole, cduck and verult as code owners June 24, 2022 20:10
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jun 24, 2022
Copy link
Collaborator

@vtomole vtomole 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

@@ -58,9 +58,12 @@ def _all_rotation_pairs():
yield (px, flip_x), (pz, flip_z)


@functools.cache
def _all_clifford_gates():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line not touched but might as well add a return type annotation while we're at it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and it made me realize this likely doesn't work since List is not hashable....so changed to tuple!

@vtomole
Copy link
Collaborator

vtomole commented Jun 24, 2022

Looks like functools.cache just got added in Python 3.9. Maybe we want to replace it with lru_cache() for now?

@vtomole
Copy link
Collaborator

vtomole commented Jun 24, 2022

Naive python question: Why do these functions have different return types?

from typing import Generator, Tuple

def tuple_of_ints() -> Tuple[int, ...]:
    return tuple(
       i for i in range(2)
    )
    
def generator_of_tuple_of_ints() -> Generator[int, None, None]:
    return (
       i for i in range(2)
    )

@dabacon
Copy link
Collaborator Author

dabacon commented Jun 24, 2022

You might think (x for x in range(2)) is a tuple, but it's not. It's a generator expression. So that's why the second one is typed as you have it. Here is a good ref https://anandology.com/python-practice-book/iterators.html

@@ -739,7 +740,7 @@ def test_multi_clifford_decompose_by_unitary():
# Construct a random clifford gate:
n, num_ops = 5, 20 # because we relied on unitary cannot test large-scale qubits
gate_candidate = [cirq.X, cirq.Y, cirq.Z, cirq.H, cirq.S, cirq.CNOT, cirq.CZ]
for seed in range(100):
for seed in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest to drop seeding here and replace it with np.random calls and a simple repetition.
The default numpy random generator is getting reproducibly, non-constantly seeded
in check/pytest. Over time there should be more randomness in its generated choices than with the 10 seeds here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@pavoljuhas
Copy link
Collaborator

LGTM, but I have noticed some strange random seeding in the test with seeds from range(0, 10) or so.
I think this should be replaced with np.random calls as the default numpy generator is seeded
from the last commit time; overall the tests would get more randomness with a standard np.random calls.

Perhaps a matter for separate PR.

@pavoljuhas pavoljuhas added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 25, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 25, 2022
@CirqBot CirqBot merged commit 1a4e418 into quantumlib:master Jun 25, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants