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

TypeError: EvalfMixin.evalf() got an unexpected keyword argument 'real' hit in transpile #12144

Closed
cqc-melf opened this issue Apr 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@cqc-melf
Copy link

cqc-melf commented Apr 5, 2024

Environment

  • Qiskit version: 1.0.2
  • Python version: 3.11, maybe more
  • Operating system: linux and mac, maybe more

What is happening?

When transpiling the circuit shown below, we hit TypeError: EvalfMixin.evalf() got an unexpected keyword argument 'real'

qiskit/circuit/parameterexpression.py", line 528, in numeric
    real_expr = self._symbol_expr.evalf(real=True)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EvalfMixin.evalf() got an unexpected keyword argument 'real'

See

real_expr = self._symbol_expr.evalf(real=True)

How can we reproduce the issue?

from qiskit import transpile
from qiskit.circuit import (
    ParameterExpression,
)
from qiskit import transpile, QuantumCircuit
import qiskit.circuit.library.standard_gates as qiskit_gates
import sympy

symb_map = {}

params = [1.5707963267948966, 1.999999999999993, 10.995574287564276]

new_qiskit_c = QuantumCircuit(1)

half = ParameterExpression(symb_map, sympy.pi / 2)
new_qiskit_c.global_phase += -params[0] / 2 - params[2] / 2
new_qiskit_c.append(
            qiskit_gates.UGate(params[1], params[0] - half, params[2] + half),
            qargs=[0],
)

qc_transpiled_again = transpile(new_qiskit_c, basis_gates=["sx", "rz", "cx", "x"])

What should happen?

No error should show up and the transpile should work?

Any suggestions?

It might be possible to use the chop parameter instead of real, but I am not sure what the intended result should be.
More details at: https://docs.sympy.org/latest/modules/core.html#sympy.core.evalf.EvalfMixin.evalf

@cqc-melf cqc-melf added the bug Something isn't working label Apr 5, 2024
@cqc-melf
Copy link
Author

cqc-melf commented Apr 5, 2024

If you need a more detailed error message or more details on other packages I am running this with, please let me know.

@jakelishman
Copy link
Member

Thanks for the report!

The problem is that you've got a direct Sympy pi instance in ParameterExpression there. We stopped using Sympy entirely for ParameterExpression in #10902 a little while back - before that, we'd dynamically use either symengine or sympy. If you're manually constructing ParameterExpression, you'll need to convert the symbols and the inner expression to symengine constructs first, but that should ideally just be a call to symengine.sympify.

@cqc-melf
Copy link
Author

cqc-melf commented Apr 5, 2024

Thank you for your help! That solved the problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants