Skip to content

Commit 667f8d9

Browse files
committed
fix Circuit.from_gates bug
1 parent f52a707 commit 667f8d9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

quimb/tensor/circuit.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,14 @@ def parse_to_gate(
14151415
)
14161416
return gate_id
14171417

1418+
if isinstance(gate_id, tuple):
1419+
# if given a tuple just unpack it
1420+
if gate_args:
1421+
raise ValueError(
1422+
"You cannot specify ``gate_args`` when supplying a tuple."
1423+
)
1424+
gate_id, gate_args = gate_id[0], gate_id[1:]
1425+
14181426
if hasattr(gate_id, "shape") and not isinstance(gate_id, str):
14191427
# raw gate (numpy strings have a shape - ignore those)
14201428

@@ -1663,8 +1671,7 @@ def __init__(
16631671

16641672
if self._ket_site_ind_id == self._bra_site_ind_id:
16651673
raise ValueError(
1666-
"The 'ket' and 'bra' site ind ids clash : "
1667-
"'{}' and '{}".format(
1674+
"The 'ket' and 'bra' site ind ids clash : '{}' and '{}".format(
16681675
self._ket_site_ind_id, self._bra_site_ind_id
16691676
)
16701677
)
@@ -1833,7 +1840,7 @@ def from_gates(cls, gates, N=None, progbar=False, **kwargs):
18331840

18341841
N = 0
18351842
for gate in gates:
1836-
gate = parse_to_gate(*gate)
1843+
gate = parse_to_gate(gate)
18371844
if gate.qubits:
18381845
N = max(N, max(gate.qubits) + 1)
18391846
if gate.controls:
@@ -4639,9 +4646,7 @@ def apply_gates(self, gates, progbar=False, **gate_opts):
46394646
)
46404647

46414648
for gate in gates:
4642-
if not isinstance(gate, Gate):
4643-
gate = parse_to_gate(*gate)
4644-
4649+
gate = parse_to_gate(gate)
46454650
self._apply_gate(gate, **gate_opts)
46464651

46474652
if progbar and (gate.total_qubit_count >= 2):

0 commit comments

Comments
 (0)