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 DeviceMetaData class. #4832

Merged
merged 5 commits into from
Jan 13, 2022
Merged

Conversation

MichaelBroughton
Copy link
Collaborator

Adds standalone DeviceMetaData class. First step in #4743 .

@MichaelBroughton MichaelBroughton requested review from cduck, vtomole and a team as code owners January 13, 2022 01:00
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jan 13, 2022
cirq-core/cirq/devices/device.py Outdated Show resolved Hide resolved
cirq-core/cirq/devices/device.py Outdated Show resolved Hide resolved

self._nx_graph = nx_graph
self._kwargs_names = kwargs.keys()
self.__dict__.update(kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Directly modifying the object dict feels super hacky to me - this will lead to cases like:

md = DeviceMetaData(qubits, nx_graph, blah=12)
# elsewhere, maybe in a different file
result = md.blah

which is difficult to trace: DeviceMetaData has no blah member variable, and using an instance other than the one initialized above will cause an error.

If we really need to store arbitrary typeless information in this object (as opposed to using subclasses which add explicitly-typed member variables), we should pack it into a Dict[str, Any].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed altogether.

cirq-core/cirq/devices/device.py Outdated Show resolved Hide resolved
cirq-core/cirq/devices/device.py Outdated Show resolved Hide resolved
Comment on lines 202 to 206
if qubits is not None:
qubits = frozenset(qubits)
self._qubits_set: Optional[FrozenSet['cirq.Qid']] = cast(
Optional[FrozenSet['cirq.Qid']], qubits
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: this would be more concise as

self._qubits_set: Optional[FrozenSet['cirq.Qid']] = (
    None if qubits is None else frozenset(qubits)
)

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jan 13, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jan 13, 2022
@CirqBot CirqBot merged commit 3a6ad87 into quantumlib:master Jan 13, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jan 13, 2022
MichaelBroughton added a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
Adds standalone DeviceMetaData class. First step in quantumlib#4743 .
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Adds standalone DeviceMetaData class. First step in quantumlib#4743 .
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Adds standalone DeviceMetaData class. First step in quantumlib#4743 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants