Skip to content

fix: Raise TypeError for string exponents in EigenGate and add test #7394

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

Conversation

luffy-orf
Copy link

@luffy-orf luffy-orf commented May 30, 2025

This PR updates Cirq’s parameterized gate logic to disallow using strings as exponents (e.g., cirq.X**"text").

  • If a string is passed as an exponent to any gate inheriting from EigenGate, a TypeError is now raised with a clear message.
  • A test is added to ensure this behavior is enforced.

Changes -

  • Added a type check in EigenGate.__pow__ to raise a TypeError if the exponent is a string.
  • Added a test in common_gates_test.py to verify that cirq.X**"text" raises the expected error.

Closes - #2936
Solved Under unitaryhack

@luffy-orf luffy-orf requested review from vtomole and a team as code owners May 30, 2025 09:23
@luffy-orf luffy-orf requested a review from mpharrigan May 30, 2025 09:23
@github-actions github-actions bot added the Size: XS <10 lines changed label May 30, 2025
@luffy-orf luffy-orf closed this Jun 1, 2025
@luffy-orf luffy-orf deleted the disallow-string-exponents-in-eigengate branch June 1, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant