qiskit-braket-provider icon indicating copy to clipboard operation
qiskit-braket-provider copied to clipboard

ParameterExpression with operations other then add, mul, neg are not translatable.

Open jcjaskula-aws opened this issue 1 year ago • 3 comments

Steps to reproduce the problem

Translating circuits like:

qiskit_circuit = QuantumCircuit(1)
v = ParameterVector("v", 2)
qiskit_circuit.rx(Parameter("a")/Parameter("b"), 0)
braket_circuit = to_braket(qiskit_circuit)

will throw an error because we serialize and parse the ast to create a FreeParameterExpression instead of relying on Sympy.

What is the current behavior?

Throws an error.

ValueError: Unsupported binary operation: <class 'ast.Div'>

What is the expected behavior?

Create a correct FreeParameterExpression.

jcjaskula-aws avatar Feb 12 '24 17:02 jcjaskula-aws

Thank you for this issue! We will look into this.

ashlhans avatar Feb 14 '24 18:02 ashlhans

Dumping some thoughts here:

  • Sympy could do heavy-lifting via Parameter.sympify() and then create the Braket FreeParameterExpression.
  • we are parsing ParameterExpression string to rename ParameterVectorElement, which conflicts with the first point.
  • Someone could always use Parameter("a")*Parameter("b") and assign inverted values to b.

jcjaskula-aws avatar Feb 16 '24 15:02 jcjaskula-aws

Division will be solved with https://github.com/amazon-braket/amazon-braket-sdk-python/pull/885

speller26 avatar Feb 21 '24 02:02 speller26