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

Abstract out auth+device+sampler boilerplate from cirq_google tutorials #4286

Merged
merged 40 commits into from Sep 14, 2021

Conversation

AnimeshSinha1309
Copy link
Contributor

Code from the tutorial notebooks has been abstracted out into a function in the cirq_google library.
The function goes by the name cirq_google.engine.engine_sampler.get_device_sampler()
All the notebooks are being refactored to use this abstraction.
Closes #4260.

Copies the boilerplate code from cirq-google tutorial notebooks and adds that as a function in library.
The imports for cirq_google package needed to be changed now that the boilerplate code is no longer in an external notebook, so fixed that.
Fixing the `get_device_sampler` function, making the part that gets the device and sampler optional so that the tutorials that use the engine can avoid it. Complete type annotations and docstring for the function.
The tutorial boilerplate has been abstracted out, so replaced that code in the notebooks with function calls. These notebooks haven't been tested yet.
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 4, 2021
@AnimeshSinha1309 AnimeshSinha1309 marked this pull request as draft July 4, 2021 22:54
Imported Tuple from typing, and fixed missing imports with TYPE_CHECKING.
Ran the autoformatter, added the cirq_google imports (sometimes as duplicate) and corrected the name of the function call.
Lint check should pass now. Type check just has 2 modules (IPython and google.colab) with no stubs. Coverage has the G-Cloud signin lines with no coverage.
@AnimeshSinha1309
Copy link
Contributor Author

The code that was copied from the tutorials includes IPython and google.colab, both of which do not have type hints. I am unable to add my stubs. This is what is making the Type check fail.
The other issue is the coverage, the authenticate_user method actually attempts to authenticate on Google cloud, I cannot provide a test project id and processor.

Unable to figure out a solution to these problems, requesting help on them.

@AnimeshSinha1309
Copy link
Contributor Author

Also, I haven't run the notebooks, they will need to be tested before this is merged. I don't think whether or not the notebooks work in all cases gets tested in the CI pipeline. Testing them with GCloud signin will be hard since I don't have an account. I have tested the call to the local noisy simulator.

@AnimeshSinha1309 AnimeshSinha1309 marked this pull request as ready for review July 6, 2021 11:13
@mpharrigan
Copy link
Collaborator

You should be able to modify the mypy.ini configuration file to ignore 3rd party libraries that lack stubs. Please check that file for examples of how we do it for other dependencies.

Maybe @wcourtney could provide some guidance on how to test google auth functions, but at the very worst you can add # coverage: ignore to skip coverage check for a given line or block

Mypy issue fixed (library stubs), Google Auth testing ignored with pragmas, function return types cleaned up.
The function prototype for auth changed, changing the same in notebooks.
Removing the option of not getting the device broke stuff in tests, fixing it.
Ran the formatter.
Had missed a not in the sampler test.
Trivial change to trigger tests, packaging had failed due to network error.
@AnimeshSinha1309
Copy link
Contributor Author

I am again done on my end. I have fixed the errors, factored out the code, and I really hope I haven't caused new ones.

Fixed the inverted logic in the Floquet calibration notebook.
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

Thanks! This really cleans things up

@mpharrigan mpharrigan added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Sep 14, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Sep 14, 2021
@CirqBot CirqBot merged commit b3fa1bf into quantumlib:master Sep 14, 2021
@CirqBot CirqBot removed 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. labels Sep 14, 2021
MichaelBroughton added a commit that referenced this pull request Sep 15, 2021
#4286 Broke our nightly build of https://quantumai.google/cirq/tutorials/google/floquet_calibration_example

Without the `--pre` flag this tutorial wouldn't pull in the latest changes and broke.

Added the `--pre` to fix this.
CirqBot pushed a commit that referenced this pull request Sep 15, 2021
https://quantumai.google/cirq/tutorials/google/floquet_calibration_example broke after #4286 (because it was missing a `--pre` flag).

Without the `--pre` flag this tutorial wouldn't pull in the latest changes and broke.

Added the `--pre` to fix this.
CirqBot pushed a commit that referenced this pull request Sep 17, 2021
#4286 introduced a new module (`qcs_notebook`) and utility method (`get_qcs_objects_for_notebook`) to abstract out boilerplate code for notebooks. 

However, all notebooks using the new method now depend on the pre-released version and should `pip install --pre cirq` instead of `pip install cirq` to work correctly. Right now, all these notebooks are broken and this PR fixes it. 

Note: In some notebooks, already existing `--pre` and `--quiet` is reordered because of recent tests which assert that pre released notebooks have the pip install statement: https://github.com/quantumlib/Cirq/blob/6ecaf0793c0d0865b09603e50fcfbc11ce567273/dev_tools/notebooks/isolated_notebook_test.py#L206 
Even though vendor notebooks (`"**/google/*.ipynb",`) are skipped from testing against cirq, I think it's good to add them to the `NOTEBOOKS_DEPENDING_ON_UNRELEASED_FEATURES` so that `--pre` can be removed in the next release. 

cc @AnimeshSinha1309 for future reference.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…ls (quantumlib#4286)

Code from the tutorial notebooks has been abstracted out into a function in the `cirq_google` library.
The function goes by the name `cirq_google.engine.engine_sampler.get_device_sampler()`
All the notebooks are being refactored to use this abstraction.
Closes quantumlib#4260.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
https://quantumai.google/cirq/tutorials/google/floquet_calibration_example broke after quantumlib#4286 (because it was missing a `--pre` flag).

Without the `--pre` flag this tutorial wouldn't pull in the latest changes and broke.

Added the `--pre` to fix this.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
quantumlib#4286 introduced a new module (`qcs_notebook`) and utility method (`get_qcs_objects_for_notebook`) to abstract out boilerplate code for notebooks. 

However, all notebooks using the new method now depend on the pre-released version and should `pip install --pre cirq` instead of `pip install cirq` to work correctly. Right now, all these notebooks are broken and this PR fixes it. 

Note: In some notebooks, already existing `--pre` and `--quiet` is reordered because of recent tests which assert that pre released notebooks have the pip install statement: https://github.com/quantumlib/Cirq/blob/6ecaf0793c0d0865b09603e50fcfbc11ce567273/dev_tools/notebooks/isolated_notebook_test.py#L206 
Even though vendor notebooks (`"**/google/*.ipynb",`) are skipped from testing against cirq, I think it's good to add them to the `NOTEBOOKS_DEPENDING_ON_UNRELEASED_FEATURES` so that `--pre` can be removed in the next release. 

cc @AnimeshSinha1309 for future reference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Google tutorial docs boilerplate
5 participants