Replies: 2 comments
-
Thanks for your question. This is a corner case where the code fails to transform tc.Circuit to qiskit Circuit. import tensorcircuit as tc
import numpy as np
K = tc.set_backend ("tensorflow")
tc.set_dtype ("complex128")
c = tc.Circuit(2)
c.H(0)
c.cnot(1, 0)
c.rz(0, theta=tc.array_to_tensor(0.2)) # the only line changed
cq = c.to_qiskit()
c.draw(output="mpl") And we will make the transformation code more universal later, by then the above code provided by you will work as expected. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The new commit fb5d510 should fix the bug, and your code can work as expected |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
import tensorcircuit as tc
import numpy as np
K = tc. set_backend ("tensorflow")
tc.set_dtype ("complex128")
c = tc.Circuit(2)
c.H(0)
c.cnot(1, 0)
c.rz(0, theta=0.2)
cq = c.to_qiskit()
c.draw(output="mpl")
Hi, could you please check the above code to draw a circuit? The following error message happens for my test:
AttributeError Traceback (most recent call last)
tensorcircuit-master\docs\source\whitepaper\3-circuits-gates.ipynb Cell 48' in <cell line: 9>()
7 c.cnot(1, 0)
8 c.rz(0, theta=0.2)
----> 9 cq = c.to_qiskit()
10 c.draw(output="mpl")
tensorcircuit\circuit.py:1483, in Circuit.to_qiskit(self)
1480 from .translation import qir2qiskit
1482 qir = self.to_qir()
-> 1483 return qir2qiskit(qir, n=self._nqubits)
tensorcircuit\translation.py:113, in qir2qiskit(qir, n)
110 qiskit_circ.unitary(wroot_op, index, label=qis_name)
111 elif gate_name in ["rx", "ry", "rz", "crx", "cry", "crz"]:
112 getattr(qiskit_circ, gate_name)(
--> 113 np.real(backend.numpy(parameters["theta"])).item(), *index
114 )
115 elif gate_name in ["orx", "ory", "orz"]:
116 getattr(qiskit_circ, "c" + gate_name[1:])(
117 np.real(backend.numpy(parameters["theta"])).item(), *index, ctrl_state=0
118 )
tensorcircuit\backends\tensorflow_backend.py:329, in TensorFlowBackend.numpy(self, a)
328 def numpy(self, a: Tensor) -> Tensor:
--> 329 return a.numpy()
AttributeError: 'float' object has no attribute 'numpy'
Beta Was this translation helpful? Give feedback.
All reactions