Skip to content

Commit

Permalink
Fix the deprecation warning for ClassicallyControlledOperation (#4780)
Browse files Browse the repository at this point in the history
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 #4763
  • Loading branch information
yjt98765 authored Dec 29, 2021
1 parent d58b58b commit 894d49e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 0 additions & 1 deletion cirq-core/cirq/ops/classically_controlled_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def _circuit_diagram_info_(

def _json_dict_(self) -> Dict[str, Any]:
return {
'cirq_type': self.__class__.__name__,
'conditions': self._conditions,
'sub_operation': self._sub_operation,
}
Expand Down
6 changes: 2 additions & 4 deletions docs/dev/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ There are several steps needed to support an object's serialization and deserial
and pass `cirq-core/cirq/protocols/json_serialization_test.py`:

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.
containing 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.

2. In `class_resolver_dictionary` within the packages's `json_resolver_cache.py` file,
for each serializable class, the `cirq_type` of the class should be mapped to the imported class
Expand Down

0 comments on commit 894d49e

Please sign in to comment.