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

Add Local implementation of abstract engine classes #4645

Merged
merged 10 commits into from
Nov 19, 2021

Conversation

dstrain115
Copy link
Collaborator

This PR creates partially implemented sub-classes that define
in-memory objects for engine functionality unlikely to be implemented
differently, such as reservations, labels, and descriptions:

AbstractLocalJob, AbstractLocalProgram,
AbstractLocalProcessor, AbstractLocalEngine

These classes follow the implementation of the production
Engine classes but use local memory to provide equivalent
functionality for testing, mocking, and local simulator use.

This is PR 2 of a three part series.

This PR creates partially implemented sub-classes that define
in-memory objects for engine functionality unlikely to be implemented
differently, such as reservations, labels, and descriptions:

AbstractLocalJob, AbstractLocalProgram,
AbstractLocalProcessor, AbstractLocalEngine

These classes follow the implementation of the production
Engine classes but use local memory to provide equivalent
functionality for testing, mocking, and local simulator use.

This is PR 2 of a three part series.
@dstrain115 dstrain115 requested review from cduck, vtomole, wcourtney and a team as code owners November 9, 2021 13:40
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 9, 2021
@CirqBot CirqBot added the size: XL lines changed >1000 label Nov 9, 2021
Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

Reviewed AbstractLocal(Engine|Job). Also see my comments from #4644, as many of the parent-class comments apply to the child class.

Will follow up with AbstractLocal(Processor|Program) reviews.

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

Reviewed AbstractLocal(Processor|Program).

cirq-google/cirq_google/engine/abstract_local_processor.py Outdated Show resolved Hide resolved
"""Returns the expected the processor should be available, if set."""
return self._expected_recovery_time

def _create_id(self, id_type: str = 'reservation') -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function header looks like it's for multiple ID types, but the body appears specific to reservations. Do we need to differentiate between types, or is the current behavior OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to resource id. I don't think the exact string matters much, but we can always improve on it later, if someone wants behavior related to resource ids.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It sounds like this will work from your comment, but to confirm: will the following behave properly?

id1 = self._create_id()                          # id1 = '.../1/reservation'
id2 = self._create_id(id_type='something_else')  # id2 = '.../2/something_else'
id3 = self._create_id()                          # id3 = '.../3/reservation'

i.e. is it OK that the two 'reservation' IDs don't have consecutive numbers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this should be fine. I think the reality is that the ids are UUIDs, not consecutive integers. We just want them to be unique. I think the one issue is that jobs should really be children of programs, but I am not going to worry about that right now.

cirq-google/cirq_google/engine/abstract_local_processor.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_program.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_program.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_program.py Outdated Show resolved Hide resolved
Copy link
Collaborator Author

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

Thanks for the thorough review. I think I addressed all comments.

cirq-google/cirq_google/engine/abstract_local_engine.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_job_test.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_job_test.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_processor.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_program.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_program.py Outdated Show resolved Hide resolved
cirq-google/cirq_google/engine/abstract_local_program.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

A couple small items left to address, then this is good to go once the part 1 PR is merged.

@MichaelBroughton
Copy link
Collaborator

Looks like there are some conflicts in merging part 1 into this.

@dstrain115
Copy link
Collaborator Author

Looks like there are some conflicts in merging part 1 into this.

Fixed. The merge conflicts were due to removing the coverage:ignore statements, which was intentional, as they are now covered by the tests in this PR.

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 19, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 19, 2021
@CirqBot CirqBot merged commit a75b215 into quantumlib:master Nov 19, 2021
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 19, 2021
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 19, 2021
@mpharrigan
Copy link
Collaborator

At least SimulatedLocalProcessor does not implement the Cirq requirement of roundtrippable reprs

@mpharrigan
Copy link
Collaborator

or JSON serializability

rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
This PR creates partially implemented sub-classes that define
in-memory objects for engine functionality unlikely to be implemented
differently, such as reservations, labels, and descriptions:

AbstractLocalJob, AbstractLocalProgram,
AbstractLocalProcessor, AbstractLocalEngine

These classes follow the implementation of the production
Engine classes but use local memory to provide equivalent
functionality for testing, mocking, and local simulator use.

This is PR 2 of a three part series.
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: XL lines changed >1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants