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

Deprecate ciruit.device everywhere. #4845

Merged
merged 7 commits into from
Jan 19, 2022

Conversation

MichaelBroughton
Copy link
Collaborator

Last item in step 1 of #4744 .

@CirqBot CirqBot added the size: XL lines changed >1000 label Jan 15, 2022
Comment on lines +157 to +159
if self._device == cirq.UNCONSTRAINED_DEVICE:
return FrozenCircuit(self, strategy=InsertStrategy.EARLIEST)
return FrozenCircuit(self, strategy=InsertStrategy.EARLIEST, device=self._device)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason I opted for this patter instead of something like:

ret_device = FrozenCircuit(self, strategy=....)
ret_device._device = self._device
return ret_device

Is because the constructor with the device argument makes non trivial behavior changes to the constructor and so that's why I opted to use this pattern in places with deprecations. Removing them once the cycle is over should be relatively easy to do since all we need to do is keep the snippet inside the if statement and delete the else block.

@@ -70,6 +73,17 @@
_DEVICE_DEP_MESSAGE = 'Attaching devices to circuits will no longer be supported.'


@contextlib.contextmanager
def _block_overlapping_dep():
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's up with this? Perhaps a line comment explaining what this is.
Also I would change dep to deprecation, since abbreviations should be avoided, especially ambiguous ones (could be dependencies)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to catch overlapping deprecation warnings. If a user calls with_device they should only see the warning for with_device and not the internal message of with_device using the constructor with the device argument as well.

cirq-core/cirq/circuits/circuit_dag.py Outdated Show resolved Hide resolved
cirq-core/cirq/circuits/frozen_circuit.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.

One concern re: JSON omission of device, otherwise LGTM

@@ -1323,11 +1343,11 @@ def save_qasm(
self._to_qasm_output(header, precision, qubit_order).save(file_path)

def _json_dict_(self):
return protocols.obj_to_dict_helper(self, ['moments', 'device'])
return protocols.obj_to_dict_helper(self, ['moments'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This confuses me a bit: we still support device everywhere, except for JSON? It seems like this and _from_json_dict_ should continue supporting device until it's removed everywhere else as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, got a little ahead of myself there. Went ahead and put device back in json. We can cut it and add the {repr,json}_inward once things are officially cut when the deprecation cycle is over.

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.

LGTM

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jan 19, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jan 19, 2022
@CirqBot CirqBot merged commit bce3002 into quantumlib:master Jan 19, 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 19, 2022
MichaelBroughton added a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: XL lines changed >1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants