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

Support gate exponentiation by Gate ** x instead of only Gate.power(x) #7473

Closed
kevinsung opened this issue Jan 4, 2022 · 3 comments · Fixed by #9030
Closed

Support gate exponentiation by Gate ** x instead of only Gate.power(x) #7473

kevinsung opened this issue Jan 4, 2022 · 3 comments · Fixed by #9030
Assignees
Labels
type: enhancement It's working, but needs polishing

Comments

@kevinsung
Copy link
Contributor

kevinsung commented Jan 4, 2022

What is the expected enhancement?

Exponentiating a gate using ** should work. It can just call gate.power. For example, it's surprising that the following code raises an error:

from qiskit.circuit.library import iSwapGate

gate = iSwapGate()
gate.power(0.5)
gate**0.5
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-9fc21b517202> in <module>
      3 gate = iSwapGate()
      4 gate.power(0.5)
----> 5 gate**0.5

TypeError: unsupported operand type(s) for ** or pow(): 'iSwapGate' and 'float'
@kevinsung kevinsung added the type: enhancement It's working, but needs polishing label Jan 4, 2022
@AshwinKul28
Copy link

HI @kevinsung,

In the above issue, you're trying to invoke ** or exponential function directly on the NumPy array. It doesn't matter even if you pass int, float or bigint it will throw an error.

for example, Below snippet is also throwing an error.
Screenshot 2022-01-13 at 2 58 38 AM

The reason behind that is, gate.power() function is not same as normal exponential **. Hence gate will not allow the combination using **.

@dmkunsman
Copy link

Should this be closed?

@kevinsung
Copy link
Contributor Author

This can be done by implementing the __pow__ magic method. Ints should be supported too.

@kevinsung kevinsung changed the title gate exponentiation with float should work Support gate exponentiation Jan 12, 2022
@Cryoris Cryoris changed the title Support gate exponentiation Support gate exponentiation by Gate ** x instead of only Gate.power(x) Jan 13, 2022
@kevinsung kevinsung self-assigned this Nov 8, 2022
@mergify mergify bot closed this as completed in #9030 Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants