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 EngineProcessorTimeSlot to cirq.google.engine #2794

Merged
merged 12 commits into from
Mar 9, 2020

Conversation

dstrain115
Copy link
Collaborator

  • This class will be a wrapper to hold timeslots for reservations.

- This class will be a wrapper to hold timeslots for reservations.
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Feb 26, 2020
Copy link
Collaborator

@wcourtney wcourtney left a comment

Choose a reason for hiding this comment

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

The Cirq Engine interface has changed a bit since the design was written. Thanks for dealing with the drift!

from typing import Optional


class EngineProcessorTimeSlotType(enum.Enum):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although it varies from the doc, we've coalesced around dropping the "Processor" from this type in the rest of the system. WDYT of EngineTimeSlot/EngineTimeSlotType?

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.

from typing import Optional


class EngineProcessorTimeSlotType(enum.Enum):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this enum be in the client library instead? e.g.,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this enum into client/..../enum.py

slot_type: EngineProcessorTimeSlotType = _DEFAULT_SLOT_TYPE
project_id: Optional[int] = None
maintenance_title: Optional[str] = None
maintenance_description: Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

The refreshed interface now consistently exposes only primary keys as fields and provides accessors that lazily load the underlying object. Consider keeping that pattern for consistency?

e.g.
https://github.com/quantumlib/Cirq/blob/master/cirq/google/engine/engine_program.py
https://github.com/quantumlib/Cirq/blob/master/cirq/google/engine/engine_job.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Used frozen=True instead of adding accessors to have a short, readable class.

@@ -94,6 +94,23 @@ class Health(enum.IntEnum):
DOWN = 2
UNAVAILABLE = 3

class TimeSlotType(enum.IntEnum):
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the API, the TimeSlotType nested inside of QuantumTimeSlot. Does this need to match to work appropriately with the gRPC client, or is the plan to translate these? I think that this code was originally generated from the API protos, so I'm guessing that they should be in sync.

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.

start_seconds: int
end_seconds: int
slot_type: enums.QuantumProcessor.TimeSlotType = _DEFAULT_TYPE
project_id: Optional[int] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

project_id should be a string..

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.

class EngineTimeSlot:
"""A python wrapping of a Quantum Engine timeslot.
"""
start_seconds: int
Copy link
Collaborator

Choose a reason for hiding this comment

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

WDYT of datetime for start and end times? Is there a reason to prefer seconds?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, this would require some additional conventions. The proto defines this as a Timestamp which is seconds since epoch:

https://cs.corp.google.com/piper///depot/google3/google/protobuf/timestamp.proto?l=125

If we define this in datetime, we have to figure out how to translate this to datetime with timezone information and watch out that we don't screw up when serializing / deserializing. (For instance, if one researcher serializes to JSON and another in the project but in a different time zone gets the timeslot and uses it.)

It's totally doable, but it adds some complexity here. Are you sure we need this information?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need it, but I'm concerned about the usability if this is the interface for viewing a processor's schedule. Time slots are read-only, and IIUC datetime.fromtimestamp() will convert to local time, so it sounds like we're just pushing that onto the users. Not a big deal yet though and I can wait to see where this goes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, changed to datetime. I figure its easier to change now than later, and we can probably create a from_proto() function once the protos are in cirq.

@dstrain115 dstrain115 merged commit 61ce1c3 into quantumlib:master Mar 9, 2020
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants