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

Use google.auth.default() in cirq_google.get_engine #4985

Merged
merged 9 commits into from
Feb 15, 2022

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Feb 11, 2022

This will pick up a default project set with gcloud config set project <project_id> or with a service account referenced by the env var GOOGLE_APPLICATION_CREDENTIALS, in addition to the GOOGLE_CLOUD_PROJECT environment variable we were checking before.

Note that when we call google.auth.default() we also get a credential object, which I'm currently discarding. I presume there's a way to pass that in to the EngineContext via service_args, which would avoid having to authenticate again, but I'm not sure what args are expected there. @wcourtney, maybe you could shed some light here?

@maffoo maffoo requested review from wcourtney, a team, vtomole, cduck and verult as code owners February 11, 2022 23:16
@maffoo maffoo requested a review from dabacon February 11, 2022 23:16
@CirqBot CirqBot added the size: S 10< lines changed <50 label Feb 11, 2022
@@ -834,7 +835,7 @@ def get_engine(project_id: Optional[str] = None) -> Engine:

Args:
project_id: If set overrides the project id obtained from the
environment variable `GOOGLE_CLOUD_PROJECT`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm overall in favor of this change and think that this is the way we should go about setting the GCP project, but it's worth noting that the GOOGLE_CLOUD_PROJECT env variable is referenced in several places in the Cirq code: https://github.com/quantumlib/Cirq/search?q=GOOGLE_CLOUD_PROJECT. If we're going to change how the project is set (by using gcloud set project), we should be consistent throughout the framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that; I'm happy to go through and clean up more of those usages. To be clear, google.auth.default() does seem to respect the GOOGLE_CLOUD_PROJECT env var, so it's fine to set the project via the environment or with gcloud set project. It'd be nice if we can include some boilerplate language about this in one location and reference that elsewhere (at least for code; notebooks should probably be self-contained). Do you have a preference about where to document this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

SGTM. It may be worth mentioning this in the "concepts" page here, but it looks like it may have been avoided to lean on the "getting started" tutorial to discuss creation.

It looks like validation only happens in one place today and that the other cases are only in documentation and tests, so maybe we should just generalize the docstrings and point them to the shared documentation (referenced above?) about what it means to "set a project". WDYT?

I don't want to spiral your change out of control, so approving now if you'd like to capture this in a followup issue instead.

Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

I am fine with this change.

@maffoo maffoo added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 15, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 15, 2022
@CirqBot CirqBot merged commit 3c89de1 into master Feb 15, 2022
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Feb 15, 2022
@CirqBot CirqBot deleted the u/maffoo/default-auth branch February 15, 2022 17:35
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Feb 15, 2022
95-martin-orion pushed a commit to 95-martin-orion/Cirq that referenced this pull request Mar 2, 2022
This will pick up a default project set with `gcloud config set project <project_id>` or with a service account referenced by the env var `GOOGLE_APPLICATION_CREDENTIALS`, in addition to the `GOOGLE_CLOUD_PROJECT` environment variable we were checking before.

Note that when we call `google.auth.default()` we also get a credential object, which I'm currently discarding. I presume there's a way to pass that in to the `EngineContext` via `service_args`, which would avoid having to authenticate again, but I'm not sure what args are expected there. @wcourtney, maybe you could shed some light here?
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
This will pick up a default project set with `gcloud config set project <project_id>` or with a service account referenced by the env var `GOOGLE_APPLICATION_CREDENTIALS`, in addition to the `GOOGLE_CLOUD_PROJECT` environment variable we were checking before.

Note that when we call `google.auth.default()` we also get a credential object, which I'm currently discarding. I presume there's a way to pass that in to the `EngineContext` via `service_args`, which would avoid having to authenticate again, but I'm not sure what args are expected there. @wcourtney, maybe you could shed some light here?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants