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

Fix the deprecation warning for ClassicallyControlledOperation #4780

Merged
merged 2 commits into from
Dec 29, 2021

Conversation

yjt98765
Copy link
Contributor

The _json_dict_ method of ClassicallyControlledOperation contains a cirq_type key, which causes a deprecation warning:

if 'cirq_type' in base_dict:
# TODO: upgrade to ValueError in v0.15
warnings.warn(
f"Found 'cirq_type': '{base_dict['cirq_type']}' in _json_dict_. "
f"Custom values of this field are not permitted, and will produce "
"an error starting in Cirq v0.15.",
DeprecationWarning,
)

It is easy to fix by removing this item. Nevertheless, the real problem is in the manual for serialization, which says:

1. The object should have a `_json_dict_` method that returns a dictionary
containing a `"cirq_type"` key as well as keys for each of the value's
attributes. If these keys do not match the names of the class' initializer
arguments, a `_from_json_dict_` class method must also be defined.
Typically the `"cirq_type"` will be the name of your class.

It says a cirq_type is required, which contradicts the code. To avoid confusing developers in the future, I have modified it.

close #4763

@yjt98765 yjt98765 requested review from cduck, vtomole and a team as code owners December 24, 2021 07:06
@yjt98765 yjt98765 requested a review from dabacon December 24, 2021 07:06
@CirqBot CirqBot added the Size: XS <10 lines changed label Dec 24, 2021
@vtomole
Copy link
Collaborator

vtomole commented Dec 28, 2021

I think this is left over from #4704. @yjt98765 Are there any other cirq_type keys left besides this one?

@yjt98765
Copy link
Contributor Author

yjt98765 commented Dec 29, 2021

Are there any other cirq_type keys left besides this one?

No. Based on code searching results, I think all the cirq_type in _json_dict_ methods have been removed in #4704. ClassicallyControlledOperation is added after #4704. In addition, there are no more such warnings when running json_serialization_test.py.

Copy link
Collaborator

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

LGTM

@vtomole vtomole added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 29, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 29, 2021
@CirqBot CirqBot merged commit 894d49e into quantumlib:master Dec 29, 2021
@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 Dec 29, 2021
@yjt98765 yjt98765 deleted the json-cirq-type branch December 30, 2021 01:16
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
…ntumlib#4780)

The `_json_dict_` method of `ClassicallyControlledOperation` contains a `cirq_type` key, which causes a deprecation warning:

https://github.com/quantumlib/Cirq/blob/01ae51eebf3b18a5cbee9fc0c697d4e1511c07f2/cirq-core/cirq/protocols/json_serialization.py#L281-L288

It is easy to fix by removing this item. Nevertheless, the real problem is in the manual for serialization, which says:

https://github.com/quantumlib/Cirq/blob/01ae51eebf3b18a5cbee9fc0c697d4e1511c07f2/docs/dev/serialization.md?plain=1#L91-L95

It says a `cirq_type` is required, which contradicts the code. To avoid confusing developers in the future, I have modified it.

close quantumlib#4763
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…ntumlib#4780)

The `_json_dict_` method of `ClassicallyControlledOperation` contains a `cirq_type` key, which causes a deprecation warning:

https://github.com/quantumlib/Cirq/blob/01ae51eebf3b18a5cbee9fc0c697d4e1511c07f2/cirq-core/cirq/protocols/json_serialization.py#L281-L288

It is easy to fix by removing this item. Nevertheless, the real problem is in the manual for serialization, which says:

https://github.com/quantumlib/Cirq/blob/01ae51eebf3b18a5cbee9fc0c697d4e1511c07f2/docs/dev/serialization.md?plain=1#L91-L95

It says a `cirq_type` is required, which contradicts the code. To avoid confusing developers in the future, I have modified it.

close quantumlib#4763
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…ntumlib#4780)

The `_json_dict_` method of `ClassicallyControlledOperation` contains a `cirq_type` key, which causes a deprecation warning:

https://github.com/quantumlib/Cirq/blob/01ae51eebf3b18a5cbee9fc0c697d4e1511c07f2/cirq-core/cirq/protocols/json_serialization.py#L281-L288

It is easy to fix by removing this item. Nevertheless, the real problem is in the manual for serialization, which says:

https://github.com/quantumlib/Cirq/blob/01ae51eebf3b18a5cbee9fc0c697d4e1511c07f2/docs/dev/serialization.md?plain=1#L91-L95

It says a `cirq_type` is required, which contradicts the code. To avoid confusing developers in the future, I have modified it.

close quantumlib#4763
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix deprecation warning for newly added ClassicallyControlledOperation
3 participants