-
Notifications
You must be signed in to change notification settings - Fork 980
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 Parameter to cirq_google #6102
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a133ca6
Add Parameter to cirq_google
dstrain115 df94e6e
Add study to __init__ so it gets picked up as a module.
dstrain115 fe22867
Fix python 3.7 import.
dstrain115 4603f23
import order
dstrain115 e33871a
Merge branch 'master' into add_parameter
vtomole 84e8951
Address review
dstrain115 315b826
Merge branch 'add_parameter' of https://github.com/dstrain115/Cirq-1 …
dstrain115 2da5b55
Update device_parameter.py
dstrain115 be76de7
Merge branch 'master' into add_parameter
dstrain115 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
cirq-google/cirq_google/json_test_data/cirq.google.DeviceParameter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"cirq_type": "cirq.google.DeviceParameter", | ||
"path": [ | ||
"test", | ||
"subdir", | ||
"key" | ||
], | ||
"idx": 4, | ||
"value": 7.5 | ||
} |
1 change: 1 addition & 0 deletions
1
cirq-google/cirq_google/json_test_data/cirq.google.DeviceParameter.repr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cirq_google.study.device_parameter.DeviceParameter(path=['test', 'subdir', 'key'], idx=4, value=7.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2023 The Cirq Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Classes for running sweeps particular to Google hardware.""" | ||
|
||
from cirq_google.study.device_parameter import DeviceParameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright 2023 The Cirq Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Any, Dict, Optional, Sequence | ||
import dataclasses | ||
from typing_extensions import Protocol | ||
import cirq | ||
|
||
|
||
class SupportsParameter(Protocol): | ||
"""Protocol for using device parameter keys. | ||
|
||
Args: | ||
path: path of the key to modify, with each sub-folder as a string | ||
entry in a list. | ||
idx: If this key is an array, which index to modify. | ||
value: value of the parameter to be set, if any. | ||
""" | ||
|
||
path: Sequence[str] | ||
idx: Optional[int] = None | ||
value: Optional[Any] = None | ||
|
||
|
||
@dataclasses.dataclass | ||
class DeviceParameter(SupportsParameter): | ||
"""Class for specifying device parameters. | ||
|
||
For instance, varying the length of pulses, timing, etc. | ||
This class is intended to be attached to a cirq.Points | ||
or cirq.Linspace sweep object as a metadata attribute. | ||
|
||
Args: | ||
path: path of the key to modify, with each sub-folder as a string | ||
entry in a list. | ||
idx: If this key is an array, which index to modify. | ||
value: value of the parameter to be set, if any. | ||
""" | ||
|
||
path: Sequence[str] | ||
idx: Optional[int] = None | ||
value: Optional[Any] = None | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
'cirq_google.study.DeviceParameter(' | ||
f'path={self.path!r}, idx={self.idx}, value={self.value!r})' | ||
) | ||
|
||
@classmethod | ||
def _json_namespace_(cls) -> str: | ||
return 'cirq.google' | ||
|
||
@classmethod | ||
def _from_json_dict_(cls, path, idx, value, **kwargs): | ||
return DeviceParameter(path=path, idx=idx, value=value) | ||
|
||
def _json_dict_(self) -> Dict[str, Any]: | ||
return cirq.obj_to_dict_helper(self, ["path", "idx", "value"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 The Cirq Developers | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import cirq | ||
import cirq_google | ||
|
||
|
||
def test_parameters(): | ||
param = cirq_google.study.DeviceParameter(path=('test', 'subdir'), idx=2, value='tmp') | ||
cirq.testing.assert_equivalent_repr(param, global_vals={'cirq_google': cirq_google}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
SupportsDeviceParameter
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.