From cd589612b2cf915ca74c8eb888f37a5949a7c38e Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Thu, 17 Nov 2016 21:11:03 -0800 Subject: [PATCH] Move DETERMINISTIC to a library setting --- abp/__init__.py | 2 ++ abp/graphstate.py | 10 ++++------ tests/mock.py | 5 ++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/abp/__init__.py b/abp/__init__.py index a2258ac..924fa75 100644 --- a/abp/__init__.py +++ b/abp/__init__.py @@ -1,3 +1,5 @@ # Alias some stuff to make imports cleaner from abp.graphstate import GraphState from abp.qi import CircuitModel + +DETERMINISTIC = False diff --git a/abp/graphstate.py b/abp/graphstate.py index eb608c4..e37f72f 100755 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -7,6 +7,7 @@ This module implements Anders and Briegel's method for fast simulation of Cliffo import itertools as it import json, random import qi, clifford, util +import abp from stabilizer import Stabilizer @@ -17,15 +18,13 @@ class GraphState(object): Internally it uses the same dictionary-of-dictionaries data structure as ``networkx``. """ - def __init__(self, data=(), deterministic=False, vop="identity"): + def __init__(self, data=(), vop="identity"): """ Construct a ``GraphState`` :param data: An iterable of nodes used to construct the graph, or an integer -- the number of nodes, or a ``nx.Graph``. - :param deterministic: If ``True``, the behaviour of the graph is deterministic up to but not including the choice of measurement outcome. This is slightly less efficient, but useful for testing. If ``False``, the specific graph representation will sometimes be random -- of course, all possible representations still map to the same state vector. :param vop: The default VOP for new qubits. Setting ``vop="identity"`` initializes qubits in :math:`|+\\rangle`. Setting ``vop="hadamard"`` initializes qubits in :math:`|0\\rangle`. """ - self.deterministic = deterministic self.adj, self.node = {}, {} try: # Cloning from a networkx graph @@ -149,7 +148,7 @@ class GraphState(object): """ others = set(self.adj[node]) - {avoid} - if self.deterministic: + if abp.DETERMINISTIC: swap_qubit = min(others) if others else avoid else: swap_qubit = others.pop() if others else avoid @@ -352,7 +351,7 @@ class GraphState(object): # Pick a friend vertex if friend == None: - if self.deterministic: + if abp.DETERMINISTIC: friend = sorted(self.adj[node].keys())[0] else: friend = next(self.adj[node].iterkeys()) @@ -511,5 +510,4 @@ class GraphState(object): g = GraphState() g.node = self.node.copy() g.adj = self.adj.copy() - g.deterministic = self.deterministic return g diff --git a/tests/mock.py b/tests/mock.py index 75da5ba..547edc4 100644 --- a/tests/mock.py +++ b/tests/mock.py @@ -3,6 +3,7 @@ Mock graphs used for testing """ import numpy as np +import abp from abp import GraphState, clifford, qi from numpy import random import nose @@ -14,6 +15,7 @@ except ImportError: # We always run with A&B's CZ table when we are testing clifford.use_old_cz() + class AndersWrapper(graphsim.GraphRegister): """ A wrapper for A&B to make the interface identical and enable equality testing """ @@ -52,7 +54,8 @@ class ABPWrapper(GraphState): """ A wrapper for abp, just to ensure determinism """ def __init__(self, nodes=[]): - super(ABPWrapper, self).__init__(nodes, deterministic=True, vop="hadamard") + abp.DETERMINISTIC = True + super(ABPWrapper, self).__init__(nodes, vop="hadamard") def print_stabilizer(self): print self.to_stabilizer()