Skip to content

Commit

Permalink
Use an own instance of Random for mapper to be reproducible
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian S. Steiger committed Jun 14, 2018
1 parent b703630 commit b5a330c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions projectq/cengines/_twodmapper.py
Expand Up @@ -95,9 +95,11 @@ def __init__(self, num_rows, num_columns, storage=1000,
self.storage = storage
self.optimization_function = optimization_function
self.num_optimization_steps = num_optimization_steps
# Randomness to pick permutations if there are too many
self._seed = 11
random.seed(self._seed)
# Randomness to pick permutations if there are too many.
# This creates an own instance of Random in order to not influence
# the bound methods of the random module which might be used in other
# places.
self._rng = random.Random(11)
# Storing commands
self._stored_commands = list()
# Logical qubit ids for which the Allocate gate has already been
Expand Down Expand Up @@ -466,8 +468,8 @@ def _run(self):
else:
permutations = []
for _ in range(self.num_optimization_steps):
permutations.append(random.sample(matchings_numbers,
self.num_rows))
permutations.append(self._rng.sample(matchings_numbers,
self.num_rows))
for permutation in permutations:
trial_swaps = self.return_swaps(old_mapping=self.current_mapping,
new_mapping=new_mapping,
Expand Down

0 comments on commit b5a330c

Please sign in to comment.