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

GridDeviceMetadata design discussion and nits. #4961

Closed
tanujkhattar opened this issue Feb 7, 2022 · 5 comments
Closed

GridDeviceMetadata design discussion and nits. #4961

tanujkhattar opened this issue Feb 7, 2022 · 5 comments
Labels
area/devices kind/health For CI/testing/release process/refactoring/technical debt items triage/discuss Needs decision / discussion, bring these up during Cirq Cynque

Comments

@tanujkhattar
Copy link
Collaborator

tanujkhattar commented Feb 7, 2022

Description of the issue
I just looked at the newly added

class GridDeviceMetadata(device.DeviceMetadata):
and have some feedback / discussion points:

  1. s/supported_gates/gateset/g ? Type of supported_gates is not clear from it's name (is it a list of supported gate instances? gate types? gate families?) and we should change it to a more descriptive name like gateset.
  2. gate_durations should be a dict from GateFamily to cirq.Duration instead of Gateset to cirq.Duration. A gateset is a collection of gates, each of which can potentially have different durations.
    • On a related note, we should consider adding a metadata, like duration, to the base GateFamily class itself. Maybe as an optional field? Maybe as a metadata that can be queried?
    • Maintaining an explicit Gateset and an explicit Dict['cirq.GateFamily', 'cirq.Duration'] in the GridDeviceMetadata looks like a bad smell. A gateset is a collection of gates, and duration is a property of gates. Why decouple them and store them independently?
  3. If the above is done, then GridDeviceMetadata would consist of just qubit_pairs and a gateset, both of which could potentially move into the Device class, avoiding an additional indirection to access qubits on a device -- (cc Matt's comment on Deprecate device.qubit_set in cirq_google. #4940)

Cirq version
0.14dev

cc @MichaelBroughton @verult @dstrain115

@tanujkhattar tanujkhattar added triage/discuss Needs decision / discussion, bring these up during Cirq Cynque kind/health For CI/testing/release process/refactoring/technical debt items area/devices labels Feb 7, 2022
@tanujkhattar
Copy link
Collaborator Author

  1. is probably not true, because GridDeviceMetadata derives from DeviceMetadata which comprises of the connectivity graph and qubit set, soGridDeviceMetadata needs to exist. But I'm still not sure why def qubit_set(self) -> FrozenSet['cirq.Qid'] needs to exist on DeviceMetadata instead of on the Device itself ?

@MichaelBroughton
Copy link
Collaborator

s/supported_gates/gateset/g ? Type of supported_gates is not clear from it's name (is it a list of supported gate instances? gate types? gate families?) and we should change it to a more descriptive name like gateset.

The name of the property on the class is gateset do we just want to change the name of the variable in the constructor ?

gate_durations should be a dict from GateFamily to cirq.Duration instead of Gateset to cirq.Duration. A gateset is a collection of gates, each of which can potentially have different durations.
On a related note, we should consider adding a metadata, like duration, to the base GateFamily class itself. Maybe as an optional field? Maybe as a metadata that can be queried?
Maintaining an explicit Gateset and an explicit Dict['cirq.GateFamily', 'cirq.Duration'] in the GridDeviceMetadata looks like a bad smell. A gateset is a collection of gates, and duration is a property of gates. Why decouple them and store them independently?

I'm fine with changing to Dict['cirq.GateFamily', 'cirq.Duration'], the point of this class is to just get the information to the users in an exploratory fashion, both GateFamily and Gateset will do this.

Maintaining an explicit Gateset and an explicit Dict['cirq.GateFamily', 'cirq.Duration'] in the GridDeviceMetadata looks like a bad smell. A gateset is a collection of gates, and duration is a property of gates. Why decouple them and store them independently?

Durations can't always be well defined by just the gates. In all cases, the duration of the gate can only be known or defined once you have a device that implements that gate. I think it makes complete sense that a gateset/gatefamily to duration mapping happen close to the device and it be clear that the device dictates this information. I don't think we should add metadata about durations to gatesets to turn their job into communicating information about groups of gates and their respective durations were they to have some known timings related to a device.

@verult
Copy link
Collaborator

verult commented Feb 7, 2022

Thanks for the suggestions!

My take:

  1. No strong preference especially since the property name is gateset.
  2. I also brought up the same point with Mike :) I agree that both forms serve the informational purpose equally since gates with the same duration can be grouped into the same gateset, but IMO a GateFamily:Duration mapping (a) is more intuitive, since a duration is associated with gates rather than gatesets, and grouping GateFamilies into a Gateset based on duration isn't the intended use of Gateset, and (b) makes the implementation of my current Devices refactor design a tad simpler.
  3. Agree with Mike that duration is associated with (gate, device) tuple.

@tanujkhattar
Copy link
Collaborator Author

tanujkhattar commented Feb 7, 2022

The name of the property on the class is gateset do we just want to change the name of the variable in the constructor ?

+1, let's make the constructor variable name match the property name.

I'm fine with changing to Dict['cirq.GateFamily', 'cirq.Duration'], the point of this class is to just get the information to the users in an exploratory fashion, both GateFamily and Gateset will do this.

On a closer look, I see that using a Gateset as a key allows you to group gates with same duration together into a single key, but I think it's better to be verbose and accept Dict['cirq.GateFamily', 'cirq.Duration'] instead. This has caused confusion more than once (eg: original design doc, cirq_google devices refactor design doc etc.

the duration of the gate can only be known or defined once you have a device that implements that gate.

Sounds good. Still curious if qubit_set needs to exist on DeviceMetadata instead of on the Device itself ?

@MichaelBroughton
Copy link
Collaborator

MichaelBroughton commented Feb 11, 2022

Closing for now. After offline discussions we agreed that in the new roles that Device take on: Devices do validate_*** and metadata stores all the exploratory items of which qubit_set is a member. Gatedurations and rename updates were here: #4963 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devices kind/health For CI/testing/release process/refactoring/technical debt items triage/discuss Needs decision / discussion, bring these up during Cirq Cynque
Projects
None yet
Development

No branches or pull requests

3 participants