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

Return processor_id and project_id in get_qcs_objects_for_notebooks #5759

Merged
merged 7 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cirq-google/cirq_google/engine/qcs_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class QCSObjectsForNotebook:
device: cirq.Device
sampler: Union[PhasedFSimEngineSimulator, ProcessorSampler]
signed_in: bool
processor_id: Optional[str]
project_id: Optional[str]

@property
def is_simulator(self):
Expand Down Expand Up @@ -90,8 +92,11 @@ def get_qcs_objects_for_notebook(
if not processors:
raise ValueError("No processors available.")
processor = processors[0]
processor_id = processor.processor_id
print(f"Available processors: {[p.processor_id for p in processors]}")
print(f"Using processor: {processor.processor_id}")
if not project_id:
project_id = processor.project_id
device = processor.get_device()
sampler = processor.get_sampler()
signed_in = True
Expand All @@ -105,7 +110,13 @@ def get_qcs_objects_for_notebook(
device = Sycamore
signed_in = False

return QCSObjectsForNotebook(device=device, sampler=sampler, signed_in=signed_in)
return QCSObjectsForNotebook(
device=device,
sampler=sampler,
signed_in=signed_in,
project_id=project_id,
processor_id=processor_id,
)


# pylint: enable=missing-raises-doc
8 changes: 5 additions & 3 deletions cirq-google/cirq_google/engine/qcs_notebook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@


def test_get_device_sampler():
result = get_qcs_objects_for_notebook()
assert result.device is cg.Sycamore
result = get_qcs_objects_for_notebook('not_a_valid_project_name')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add tests using the new fields, or would that break some QCS behavior?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it'd be good for the tests to continue to exercise the no-arguments call variant. Perhaps we can do both? (We already exercise passing both arguments on line 28 below.)

assert isinstance(result.device, cg.GridDevice)
assert not result.signed_in
assert isinstance(result.sampler, cg.PhasedFSimEngineSimulator)
assert result.is_simulator

# Note: if running locally with application default credentials,
# you actually will be signed_in
result = get_qcs_objects_for_notebook("", "")
assert not result.signed_in
assert isinstance(result.device, cg.GridDevice)