1. Erik Bray
  2. pyqc

Commits

Erik Bray  committed c2eae77

Fix another slight bug in Circuit.from_gate--this code is a really a mess and will have to be cleaned up later.

  • Participants
  • Parent commits 11ee472
  • Branches master

Comments (0)

Files changed (2)

File pyqc/circuit.py

View file
             return cls(gate._instructions)
         elif not isinstance(gate, _CompoundGate):
             # A trivial Circuit with a single gate
-            return cls([(gate, tuple(range(gate.n_qubits)))])
+            return cls([(gate, _get_default_gate_inputs(gate))])
         elif not isinstance(gate, GateBase):
             raise ValueError(
                 "Circuit.from_gate only accepts pyqc.Gate objects.")

File pyqc/gates.py

View file
     if isinstance(gate, SwapGate):
         return (0, gate.n_qubits - 1)
     elif isinstance(gate, ControlledGate):
-        target = gate._controlled_gate
-        return (tuple(range(gate.n_control)) +
-                tuple(range(gate.n_qubits - target.n_qubits,
-                            gate.n_qubits)))
+        # TODO: This part *really* needs to be refactored :/
+        controls = []
+        target = None
+        for idx, inp in enumerate(gate._input_map):
+            if inp == 'c':
+                controls.append(idx)
+            elif inp == 't' and target is None:
+                target = idx
+
+        n_target = gate._controlled_gate.n_qubits
+        return tuple(controls) + tuple(range(target, target + n_target))
     else:
         return tuple(range(gate.n_qubits))