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

MatrixGate names don't survive serialization #6026

Merged
merged 1 commit into from
Mar 3, 2023
Merged

MatrixGate names don't survive serialization #6026

merged 1 commit into from
Mar 3, 2023

Conversation

markedmiston
Copy link
Contributor

Closes #5999

@markedmiston markedmiston requested review from a team, vtomole and cduck as code owners March 3, 2023 17:19
@markedmiston markedmiston requested a review from viathor March 3, 2023 17:19
Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

LGTM with a minor comment.

@@ -114,11 +114,11 @@ def with_name(self, name: str) -> 'MatrixGate':
return MatrixGate(self._matrix, name=name, qid_shape=self._qid_shape, unitary_check=False)

def _json_dict_(self) -> Dict[str, Any]:
return {'matrix': self._matrix.tolist(), 'qid_shape': self._qid_shape}
return {'matrix': self._matrix.tolist(), 'qid_shape': self._qid_shape, **({'name': self._name} if self._name else {})}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Strictly speaking this sends empty string to None after serialization+deserialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we consider an empty string as a valid name? If so, I’ll update the check to more explicitly check None.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, at present the empty string is accepted by the ctor, so let's make sure it works in serde, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I've updated the check logic and added an empty name test.

@viathor viathor merged commit c8f7a02 into quantumlib:master Mar 3, 2023
@markedmiston markedmiston deleted the 5999 branch March 3, 2023 20:21
richrines1 added a commit to Infleqtion/client-superstaq that referenced this pull request Jul 25, 2023
fixes #637

(this was broken by #626, but didn't show up because
quantumlib/Cirq#6026 wasn't merged into non-dev
cirq until version 1.2.0)
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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatrixGate names don't survive serialization
2 participants