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

Test deserializer on infinite recursion. #4315

Merged
merged 2 commits into from Jul 13, 2021

Conversation

95-martin-orion
Copy link
Collaborator

Fixes #4304.

To be precise, this was already working: because the deserializer does not append constants to the deserialized_constants map until it finishes deserializing them, it is naturally unable to deserialize a recursive subcircuit. This PR just adds the test.

Note that the serializer will still happily attempt (and fail) to serialize CircuitOperations that exhibit infinite recursion. We allow this because CircuitOperation is an immutable type; unless you intentionally circumvent the safeguards that prevent mutation (as shown in the test), it is not possible to define a CircuitOperation that contains itself.

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 12, 2021
@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jul 13, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jul 13, 2021
@CirqBot CirqBot merged commit 7407a28 into quantumlib:master Jul 13, 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 Jul 13, 2021
@95-martin-orion 95-martin-orion deleted the cirq-subcirq-finite branch March 10, 2022 21:42
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Fixes quantumlib#4304.

To be precise, this was already working: because the deserializer does not append constants to the `deserialized_constants` map until it finishes deserializing them, it is naturally unable to deserialize a recursive subcircuit. This PR just adds the test.

Note that the _serializer_ will still happily attempt (and fail) to serialize CircuitOperations that exhibit infinite recursion. We allow this because `CircuitOperation` is an immutable type; unless you intentionally circumvent the safeguards that prevent mutation (as shown in the test), it is not possible to define a `CircuitOperation` that contains itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent deserialization of infinitely-recursive CircuitOperations
3 participants