Skip to content

Commit

Permalink
Edit tags directly instead of using CommandModifier in BasicEngine.al…
Browse files Browse the repository at this point in the history
…locate_qubit (#114)
  • Loading branch information
Strilanc authored and damiansteiger committed Jun 15, 2017
1 parent 4b60fd0 commit 74e593c
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions projectq/cengines/_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,14 @@ def allocate_qubit(self, dirty=False):
"""
new_id = self.main_engine.get_new_qubit_id()
qb = Qureg([Qubit(self, new_id)])
cmd = Command(self, Allocate, (qb,))
if dirty:
from projectq.meta import DirtyQubitTag
if self.is_meta_tag_supported(DirtyQubitTag):
oldnext = self.next_engine

def cmd_modifier(cmd):
assert(cmd.gate == Allocate)
cmd.tags += [DirtyQubitTag()]
return cmd
self.next_engine = projectq.cengines.CommandModifier(
cmd_modifier)
self.next_engine.next_engine = oldnext
self.send([Command(self, Allocate, (qb,))])
self.next_engine = oldnext
self.main_engine.active_qubits.add(qb[0])
cmd.tags += [DirtyQubitTag()]
self.main_engine.dirty_qubits.add(qb[0].id)
return qb

self.send([Command(self, Allocate, (qb,))])
self.main_engine.active_qubits.add(qb[0])
self.send([cmd])
return qb

def allocate_qureg(self, n):
Expand Down

0 comments on commit 74e593c

Please sign in to comment.