pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/tensorflow/quantum/pull/1020

hub.githubassets.com/assets/actions-902e75f4f51a80db.css" /> Reject multi-qubit noise channels with clear error message by ChungusLord123 · Pull Request #1020 · tensorflow/quantum · GitHub
Skip to content

Reject multi-qubit noise channels with clear error message#1020

Open
ChungusLord123 wants to merge 1 commit intotensorflow:masterfrom
ChungusLord123:fix/reject-multi-qubit-noise-channels
Open

Reject multi-qubit noise channels with clear error message#1020
ChungusLord123 wants to merge 1 commit intotensorflow:masterfrom
ChungusLord123:fix/reject-multi-qubit-noise-channels

Conversation

@ChungusLord123
Copy link
Copy Markdown

@ChungusLord123 ChungusLord123 commented Mar 19, 2026

Summary

  • TFQ only supports single-qubit noise channels, but there was no validation to catch multi-qubit channels like cirq.asymmetric_depolarize(error_probabilities={'XX': 0.1}). This led to cryptic errors downstream in the C++ parser, which silently ignored the second qubit.
  • Added an early validation check in the serializer that rejects multi-qubit noise channels with a clear error message explaining the limitation and suggesting .on_each() as a workaround.
  • All 8 channel serializers are now guarded, along with a corresponding test.

Fixes #686

Test plan

  • Existing serializer tests pass (single-qubit channels still serialize correctly)
  • New test_serialize_multi_qubit_noise_channel test verifies multi-qubit channels are rejected with a clear error

P.S. I'm a high school student interested in quantum computing — happy to discuss further or iterate on the patch if helpful.

TFQ only supports single-qubit noise channels, but there was no
validation to catch multi-qubit channels like
cirq.asymmetric_depolarize(error_probabilities={'XX': 0.1}).
This led to cryptic errors downstream in the C++ parser, which
silently ignored the second qubit.

Added an early validation check in the serializer that rejects
multi-qubit noise channels with a clear error message explaining
the limitation and suggesting .on_each() as a workaround. All 8
channel serializers are now guarded, along with a corresponding test.

P.S. I'm a high school student interested in quantum computing —
happy to discuss further or iterate on the patch if helpful.

Fixes tensorflow#686
@ChungusLord123 ChungusLord123 marked this pull request as draft March 19, 2026 02:49
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of cryptic errors from multi-qubit noise channels by introducing an early validation check in the serializer. The implementation adds a check to all 8 noise channel serializers, raising a clear ValueError for unsupported multi-qubit channels. The accompanying test verifies the new behavior. The changes are well-implemented and solve the problem described. I have one suggestion to enhance the test coverage by including the specific channel type that motivated this fix.

Comment on lines +723 to +731
def test_serialize_multi_qubit_noise_channel(self):
"""Ensure multi-qubit noise channels are rejected with clear error."""
q0 = cirq.GridQubit(0, 0)
q1 = cirq.GridQubit(0, 1)
multi_qubit_circuit = cirq.Circuit(
cirq.DepolarizingChannel(p=0.1, n_qubits=2)(q0, q1))
with self.assertRaisesRegex(ValueError,
"Multi-qubit noise channels"):
serializer.serialize_circuit(multi_qubit_circuit)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Great job on adding a test for this new validation! To make it more robust, I suggest expanding it to also test cirq.asymmetric_depolarize, which was the motivating example from the issue description. This will ensure that channels defined by error_probabilities with multi-qubit Pauli strings are also correctly rejected.

Additionally, the n_qubits argument in cirq.DepolarizingChannel is deprecated. It's better to omit it and let cirq infer the number of qubits from the on() call.

Suggested change
def test_serialize_multi_qubit_noise_channel(self):
"""Ensure multi-qubit noise channels are rejected with clear error."""
q0 = cirq.GridQubit(0, 0)
q1 = cirq.GridQubit(0, 1)
multi_qubit_circuit = cirq.Circuit(
cirq.DepolarizingChannel(p=0.1, n_qubits=2)(q0, q1))
with self.assertRaisesRegex(ValueError,
"Multi-qubit noise channels"):
serializer.serialize_circuit(multi_qubit_circuit)
def test_serialize_multi_qubit_noise_channel(self):
"""Ensure multi-qubit noise channels are rejected with clear error."""
q0 = cirq.GridQubit(0, 0)
q1 = cirq.GridQubit(0, 1)
depol_circuit = cirq.Circuit(
cirq.DepolarizingChannel(p=0.1)(q0, q1))
with self.assertRaisesRegex(ValueError, "Multi-qubit noise channels"):
serializer.serialize_circuit(depol_circuit)
asym_depol_circuit = cirq.Circuit(
cirq.asymmetric_depolarize(error_probabilities={'XX': 0.1})(q0, q1))
with self.assertRaisesRegex(ValueError, "Multi-qubit noise channels"):
serializer.serialize_circuit(asym_depol_circuit)

@ChungusLord123 ChungusLord123 marked this pull request as ready for review March 19, 2026 02:51
@tensorflow tensorflow deleted a comment from gemini-code-assist Bot Mar 27, 2026
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.

Multi qubit noise channels and noisy training.

1 participant

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy