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

No support for symbolic parameters for MatrixGate (U-gate) #6810

Open
vili-1 opened this issue Nov 30, 2024 · 4 comments
Open

No support for symbolic parameters for MatrixGate (U-gate) #6810

vili-1 opened this issue Nov 30, 2024 · 4 comments
Labels
kind/feature-request Describes new functionality triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet

Comments

@vili-1
Copy link

vili-1 commented Nov 30, 2024

Is your feature request related to a use case or problem? Please describe.
Cirq does not currently support symbolic parameters, such as sympy.Symbol, for the MatrixGate (U-gate). While symbolic parameters are supported in other gates like rx, ry, and rz, the same functionality is not available for custom gates using MatrixGate.
The error below is raised when attempting to simulate the circuit with a symbolic parameter:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule 'safe'.

Describe the solution you'd like
Expected that Cirq would handle symbolic parameters in the MatrixGate and allow for symbolic computation during simulation, just as it does with gates like rx, ry, and rz. Qiskit handles symbolic parameters using its Parameter() class, including for U-gates.

[optional] Describe alternatives/workarounds you've considered

[optional] Additional context (e.g. screenshots)

What is the urgency from your perspective for this issue? Is it blocking important work?

P3 - I'm not really blocked by it, it is an idea I'd like to discuss / suggestion based on principle

@vili-1 vili-1 added the kind/feature-request Describes new functionality label Nov 30, 2024
@NoureldinYosri NoureldinYosri added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Dec 11, 2024
@mhucka
Copy link
Contributor

mhucka commented Dec 11, 2024

Discussed during Cirq Cynq 2024-12-11: MatrixGate is documented as behaving this way. It is not clear on the benefits would be. Also, it may have performance implications.

@vili-1 would you be able to discuss some use cases that would be helped by such a change?

@mhucka mhucka added triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Dec 11, 2024
@chriseclectic
Copy link

The MatrixGate is defined as a 2x2 numeric unitary matrix, the qiskit equivalent gate would be UnitaryGate which also does not support symbolic arguments. I would strongly advise against adding symbolic support to this gate since it would have strong performance implications in circuit transformations, and you can no longer validate that the input is a valid unitary until you know the parameter values (and the parameters could also be complex not just floats).

In qiskit UGates are a different, since they are parameterized in a manner that is guaranteed to unitary for float parameter values, and hence can be reasonable reasoned about symbolically in circuit transformations. I'm not sure there is an equivalent in cirq (maybe one of the devs can comment), but if not you could use symbols with a Euler angle decomposition, eg rz(a) - rx(b) - rz(c), to symbolically parameterize an arbitrary single qubit gate.

@chriseclectic
Copy link

@vili-1 to follow up on my above comment I think the cirq gate you would want is cirq.PhasedZXGate. It's equivalent to the qiskit UGate up to a global phase and supports symbolic parameters.

@vili-1
Copy link
Author

vili-1 commented Dec 19, 2024

Discussed during Cirq Cynq 2024-12-11: MatrixGate is documented as behaving this way. It is not clear on the benefits would be. Also, it may have performance implications.

@vili-1 would you be able to discuss some use cases that would be helped by such a change?

Symbolic parameters, in general, can make it much easier to simplify and optimise circuits algebraically before numerical evaluations. In Quantum Machine Learning models, for example, they can optimise parameters during training. Or in Variational Quantum Algorithms, symbolic parameters for custom gates can be handy where they can represent tunable operations in hybrid quantum-classical workflows.

We’re a group of academic researchers working on fuzz testing quantum simulators and building a solid model that researchers can use in the broader scientific context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature-request Describes new functionality triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet
Projects
None yet
Development

No branches or pull requests

4 participants