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

Enforce [namespace.]classname format for cirq_type #4698

Closed
95-martin-orion opened this issue Nov 22, 2021 · 2 comments · Fixed by #4704
Closed

Enforce [namespace.]classname format for cirq_type #4698

95-martin-orion opened this issue Nov 22, 2021 · 2 comments · Fixed by #4704
Assignees
Labels
kind/design-issue A conversation around design

Comments

@95-martin-orion
Copy link
Collaborator

The type-serialization behavior added in #4693 made an implicit assumption that Cirq objects use object.__class__.__name__ for the "cirq_type" field of their JSON representation, optionally prepended with a namespace. This is consistent with existing Cirq types, but until that PR it was merely a convention; now that code depends on it, we ought to enforce it.

More specifically, this issue recommends moving assignment of the cirq_type JSON field from the _json_dict_ magic method of serializable classes into the cirq.to_json protocol. As discussed in the linked issue, this will provide consistent behavior and reduce code redundancy.

@95-martin-orion 95-martin-orion added the kind/design-issue A conversation around design label Nov 22, 2021
@95-martin-orion 95-martin-orion self-assigned this Nov 22, 2021
@95-martin-orion
Copy link
Collaborator Author

CC @mpharrigan

@mpharrigan
Copy link
Collaborator

A change that could get us most of the way there is modifying the behavior of obj_to_dict_helper

CirqBot pushed a commit that referenced this issue Nov 24, 2021
Fixes #4698.

This enforces the `'cirq_type': [<namespace>.]<classname>` convention for JSON serialization by assigning the "cirq_type" field in our protocols instead of in each class. Any external users who define a "cirq_type" will see a warning about this; after a deprecation cycle, we will begin raising errors to prevent explicit definition of "cirq_type" in classes.
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
Fixes quantumlib#4698.

This enforces the `'cirq_type': [<namespace>.]<classname>` convention for JSON serialization by assigning the "cirq_type" field in our protocols instead of in each class. Any external users who define a "cirq_type" will see a warning about this; after a deprecation cycle, we will begin raising errors to prevent explicit definition of "cirq_type" in classes.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
Fixes quantumlib#4698.

This enforces the `'cirq_type': [<namespace>.]<classname>` convention for JSON serialization by assigning the "cirq_type" field in our protocols instead of in each class. Any external users who define a "cirq_type" will see a warning about this; after a deprecation cycle, we will begin raising errors to prevent explicit definition of "cirq_type" in classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/design-issue A conversation around design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants