Skip to content

Commit

Permalink
Simplify BasicEngine.deallocate_qubit (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc authored and thomashaener committed May 14, 2017
1 parent 7256998 commit ad257db
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions projectq/cengines/_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,12 @@ def deallocate_qubit(self, qubit):
if qubit.id == -1:
raise ValueError("Already deallocated.")

if qubit.id not in self.main_engine.dirty_qubits:
self.send([Command(self, Deallocate, ([qubit],))])
else:
from projectq.meta import DirtyQubitTag
oldnext = self.next_engine

def cmd_modifier(cmd):
assert(cmd.gate == Deallocate)
cmd.tags += [DirtyQubitTag()]
return cmd
self.next_engine = projectq.cengines.CommandModifier(
cmd_modifier)
self.next_engine.next_engine = oldnext
self.send([Command(self, Deallocate, ([qubit],))])
self.next_engine = oldnext
from projectq.meta import DirtyQubitTag
is_dirty = qubit.id in self.main_engine.dirty_qubits
self.send([Command(self,
Deallocate,
(Qureg([qubit]),),
tags=[DirtyQubitTag()] if is_dirty else [])])

def is_meta_tag_supported(self, meta_tag):
"""
Expand Down

0 comments on commit ad257db

Please sign in to comment.