-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
qiskit.qasm3.dumps
raise TypeError: only length-1 arrays can be converted to Python scalars
#13362
Comments
Hi, I just reproduced the error and would like to work on this as my first contribution to Qiskit. |
@ldi18 feel free to go ahead. As far as I can see, this is a problem with QASM3 operating on the |
@gadial When I move the complex-to-string conversion into a function and apply it to each matrix element, def complex_to_str(inpt):
"""Convert a complex number to a string with formatting."""
complex_inpt = complex(inpt)
real, imag = map(normalize, [complex_inpt.real, complex_inpt.imag])
jstr = "\\jmath" if output == "latex" else "j"
if real == "0" and imag != "0":
str_out = imag + jstr
elif real != "0" and imag != "0":
op_str = "+"
# Remove + if imag negative except for latex fractions
if complex_inpt.imag < 0 and (output != "latex" or "\\frac" not in imag):
op_str = ""
str_out = f"{real}{op_str}{imag}{jstr}"
else:
str_out = real
return str_out
if isinstance(inpt, np.ndarray):
return np.reshape([complex_to_str(val) for val in inpt.flatten()], inpt.shape)
return complex_to_str(inpt) I get the following qasm3 string:
When importing the string with |
I don't think you should handle the matrix elements. In QASM2 the matrix params do not appear on the output; it adds the definition of the gate (i.e. a circuit composed of basic gates which implements it), and I guess QASM3 should do this as well. |
Environment
What is happening?
A numpy type error raised during the execution of
qiskit.qasm3.dumps
.How can we reproduce the issue?
or
What should happen?
I should be able to dump this circuit to QASM3 because
qiskit.qasm2.dumps
can successfully dump this circuit.Any suggestions?
This issue appears to be mentioned in #12013 (comment)
The text was updated successfully, but these errors were encountered: