| @@ -1,4 +1,5 @@ | |||||
| # Alias some stuff to make imports cleaner | # Alias some stuff to make imports cleaner | ||||
| from __future__ import absolute_import | |||||
| from abp.graphstate import GraphState | from abp.graphstate import GraphState | ||||
| from abp.nxgraphstate import NXGraphState | from abp.nxgraphstate import NXGraphState | ||||
| from abp.qi import CircuitModel | from abp.qi import CircuitModel | ||||
| @@ -2,6 +2,7 @@ | |||||
| Copied from Anders' original C++ implementation | Copied from Anders' original C++ implementation | ||||
| S. Anders, H. J. Briegel: Fast Simulation of Stabilizer Circuits using a Graph State Formalism quant-ph/0504117 | S. Anders, H. J. Briegel: Fast Simulation of Stabilizer Circuits using a Graph State Formalism quant-ph/0504117 | ||||
| """ | """ | ||||
| from __future__ import absolute_import | |||||
| import numpy as np | import numpy as np | ||||
| cz_table = ((((1, 0, 0), (1, 0, 0), (1, 0, 3), (1, 0, 3), (1, 0, 5), (1, 0, 5), | cz_table = ((((1, 0, 0), (1, 0, 0), (1, 0, 3), (1, 0, 3), (1, 0, 5), (1, 0, 5), | ||||
| (1, 0, 6), (1, 0, 6), (0, 3, 8), (0, 3, 8), (0, 0, 10), (0, 0, 10), | (1, 0, 6), (1, 0, 6), (0, 3, 8), (0, 3, 8), (0, 0, 10), (0, 0, 10), | ||||
| @@ -3,12 +3,15 @@ This program computes lookup tables and stores them as tables.py and tables.js | |||||
| # TODO: clifford naming discrepancy | # TODO: clifford naming discrepancy | ||||
| """ | """ | ||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| import numpy as np | import numpy as np | ||||
| import itertools as it | import itertools as it | ||||
| from functools import reduce | from functools import reduce | ||||
| from os.path import dirname, join, split | from os.path import dirname, join, split | ||||
| import json | import json | ||||
| from . import qi, clifford | from . import qi, clifford | ||||
| from six.moves import range | |||||
| DECOMPOSITIONS = ( | DECOMPOSITIONS = ( | ||||
| @@ -51,8 +54,8 @@ def find_cz(bond, c1, c2, commuters, state_table): | |||||
| target = qi.normalize_global_phase(target) | target = qi.normalize_global_phase(target) | ||||
| # Choose the sets to search over | # Choose the sets to search over | ||||
| s1 = commuters if c1 in commuters else range(24) | |||||
| s2 = commuters if c2 in commuters else range(24) | |||||
| s1 = commuters if c1 in commuters else list(range(24)) | |||||
| s2 = commuters if c2 in commuters else list(range(24)) | |||||
| # Find a match | # Find a match | ||||
| for bondp, c1p, c2p in it.product([0, 1], s1, s2): | for bondp, c1p, c2p in it.product([0, 1], s1, s2): | ||||
| @@ -173,7 +176,7 @@ def get_display_table(unitaries): | |||||
| c = qi.CircuitModel(1) | c = qi.CircuitModel(1) | ||||
| c.act_local_rotation(0, u) | c.act_local_rotation(0, u) | ||||
| state = c.state.round(2) | state = c.state.round(2) | ||||
| print("{:.2f}, {:.2f}".format(state[0][0], state[1][0])) | |||||
| print(("{:.2f}, {:.2f}".format(state[0][0], state[1][0]))) | |||||
| def compute_everything(): | def compute_everything(): | ||||
| @@ -40,7 +40,10 @@ The complete set of aliases for single-qubit Cliffords is as follows: | |||||
| """ | """ | ||||
| from tables import * | |||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| from .tables import * | |||||
| from six.moves import range | |||||
| # Aliases | # Aliases | ||||
| identity = by_name["identity"] | identity = by_name["identity"] | ||||
| @@ -51,6 +54,15 @@ pz = by_name["pz"] | |||||
| msqx_h = by_name["msqx_h"] | msqx_h = by_name["msqx_h"] | ||||
| sqz_h = by_name["sqz_h"] | sqz_h = by_name["sqz_h"] | ||||
| class Thing(object): | |||||
| def __init__(self): | |||||
| """ Constructor """ | |||||
| return None | |||||
| def hunt(self): | |||||
| """ Pete is cool """ | |||||
| pass | |||||
| def conjugate(operator, unitary): | def conjugate(operator, unitary): | ||||
| """ Returns transform * vop * transform^dagger and a phase in {+1, -1} """ | """ Returns transform * vop * transform^dagger and a phase in {+1, -1} """ | ||||
| return measurement_table[operator, unitary] | return measurement_table[operator, unitary] | ||||
| @@ -73,14 +85,13 @@ def is_diagonal(v): | |||||
| """ Checks if a VOP is diagonal or not """ | """ Checks if a VOP is diagonal or not """ | ||||
| return v in {0, 3, 5, 6} | return v in {0, 3, 5, 6} | ||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| from itertools import groupby | from itertools import groupby | ||||
| for i in range(24): | for i in range(24): | ||||
| members = [key for key, value in list(by_name.items()) if value == i and str(key)!=str(i)] | members = [key for key, value in list(by_name.items()) if value == i and str(key)!=str(i)] | ||||
| members = sorted(members, key=len) | members = sorted(members, key=len) | ||||
| print("* {}: {}".format(i, ", ".join(members))) | |||||
| print(("* {}: {}".format(i, ", ".join(members)))) | |||||
| @@ -4,12 +4,16 @@ | |||||
| This module implements Anders and Briegel's method for fast simulation of Clifford circuits. | This module implements Anders and Briegel's method for fast simulation of Clifford circuits. | ||||
| """ | """ | ||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| import itertools as it | import itertools as it | ||||
| import json, random | import json, random | ||||
| from . import qi, clifford, util | from . import qi, clifford, util | ||||
| import abp | import abp | ||||
| from .stabilizer import Stabilizer | from .stabilizer import Stabilizer | ||||
| import requests | import requests | ||||
| from six.moves import range | |||||
| from six.moves import zip | |||||
| class GraphState(object): | class GraphState(object): | ||||
| @@ -63,12 +67,12 @@ class GraphState(object): | |||||
| self._del_node(node) | self._del_node(node) | ||||
| def _add_node(self, node, **kwargs): | def _add_node(self, node, **kwargs): | ||||
| """ Add a node. | |||||
| """ Add a node. | |||||
| By default, nodes are initialized with ``vop=``:math:`I`, i.e. they are in the :math:`|+\\rangle` state. | By default, nodes are initialized with ``vop=``:math:`I`, i.e. they are in the :math:`|+\\rangle` state. | ||||
| """ | """ | ||||
| if node in self.node: | if node in self.node: | ||||
| print("Warning: node {} already exists".format(node)) | |||||
| print(("Warning: node {} already exists".format(node))) | |||||
| return | return | ||||
| default = kwargs.get("default", "identity") | default = kwargs.get("default", "identity") | ||||
| @@ -91,7 +95,7 @@ class GraphState(object): | |||||
| >>> g._add_node(0, label="fred", position=(1,2,3)) | >>> g._add_node(0, label="fred", position=(1,2,3)) | ||||
| >>> g.node[0]["label"] | >>> g.node[0]["label"] | ||||
| fred | |||||
| fred | |||||
| """ | """ | ||||
| kwargs["vop"] = clifford.by_name[ | kwargs["vop"] = clifford.by_name[ | ||||
| @@ -500,17 +504,17 @@ class GraphState(object): | |||||
| self.url = requests.get("https://abv.peteshadbolt.co.uk/").url | self.url = requests.get("https://abv.peteshadbolt.co.uk/").url | ||||
| data = json.dumps(self.to_json(stringify=True)) | data = json.dumps(self.to_json(stringify=True)) | ||||
| print("Shared state to {}".format(self.url)) | |||||
| print(("Shared state to {}".format(self.url))) | |||||
| return requests.post("{}/graph".format(self.url), data=data) | return requests.post("{}/graph".format(self.url), data=data) | ||||
| def pull(self, url=None): | def pull(self, url=None): | ||||
| """ Loads the state from the server """ | """ Loads the state from the server """ | ||||
| if url: | |||||
| if url: | |||||
| self.url = url | self.url = url | ||||
| response = requests.get("{}/graph".format(self.url)) | response = requests.get("{}/graph".format(self.url)) | ||||
| self.from_json(json.loads(response.content)) | self.from_json(json.loads(response.content)) | ||||
| @@ -1,3 +1,4 @@ | |||||
| from __future__ import absolute_import | |||||
| import networkx as nx | import networkx as nx | ||||
| import numpy as np | import numpy as np | ||||
| from . import graphstate | from . import graphstate | ||||
| @@ -6,9 +6,12 @@ Exposes a few basic QI operators | |||||
| And a circuit-model simulator | And a circuit-model simulator | ||||
| """ | """ | ||||
| from __future__ import absolute_import | |||||
| import numpy as np | import numpy as np | ||||
| import itertools as it | import itertools as it | ||||
| from fractions import Fraction | from fractions import Fraction | ||||
| from six.moves import range | |||||
| from six.moves import zip | |||||
| def hermitian_conjugate(u): | def hermitian_conjugate(u): | ||||
| """ Shortcut to the Hermitian conjugate """ | """ Shortcut to the Hermitian conjugate """ | ||||
| @@ -2,8 +2,10 @@ | |||||
| Implements a simple Stabilizer object. | Implements a simple Stabilizer object. | ||||
| """ | """ | ||||
| from __future__ import absolute_import | |||||
| import itertools as it | import itertools as it | ||||
| from abp import clifford | from abp import clifford | ||||
| from six.moves import map | |||||
| I = clifford.identity | I = clifford.identity | ||||
| X = clifford.px | X = clifford.px | ||||
| @@ -1,3 +1,4 @@ | |||||
| from __future__ import absolute_import | |||||
| import numpy as np | import numpy as np | ||||
| # Define lookup tables | # Define lookup tables | ||||
| @@ -1,10 +1,13 @@ | |||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| from abp import NXGraphState | from abp import NXGraphState | ||||
| from abp.util import xyz | from abp.util import xyz | ||||
| import networkx as nx | import networkx as nx | ||||
| from six.moves import range | |||||
| n = 10 | n = 10 | ||||
| g = NXGraphState(list(range(n))) | g = NXGraphState(list(range(n))) | ||||
| nx.set_node_attributes(g, "color", "red") | nx.set_node_attributes(g, "color", "red") | ||||
| g.add_edges_from([i, i+1] for i in range(n-1)) | g.add_edges_from([i, i+1] for i in range(n-1)) | ||||
| print(g.node[0]["color"]) | |||||
| print((g.node[0]["color"])) | |||||
| @@ -1,3 +1,5 @@ | |||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| from abp import GraphState | from abp import GraphState | ||||
| edges = (0, 1), (1, 2), (2, 0), (0, 3), (100, 200) | edges = (0, 1), (1, 2), (2, 0), (0, 3), (100, 200) | ||||
| @@ -7,5 +9,5 @@ g.act_circuit((edge, "cz") for edge in edges) | |||||
| g.act_local_rotation(3, 9) | g.act_local_rotation(3, 9) | ||||
| print(g.to_stabilizer()) | |||||
| print((g.to_stabilizer())) | |||||
| @@ -1,6 +1,8 @@ | |||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| from abp import GraphState | from abp import GraphState | ||||
| psi = GraphState() | psi = GraphState() | ||||
| psi.pull("https://abv.peteshadbolt.co.uk/dakota-illinois-nuts-blue") | psi.pull("https://abv.peteshadbolt.co.uk/dakota-illinois-nuts-blue") | ||||
| print psi | |||||
| print(psi) | |||||
| @@ -1,9 +1,13 @@ | |||||
| from __future__ import absolute_import | |||||
| from __future__ import print_function | |||||
| from abp import GraphState | from abp import GraphState | ||||
| from abp.util import xyz | from abp.util import xyz | ||||
| import numpy as np | import numpy as np | ||||
| import time | import time | ||||
| import itertools | import itertools | ||||
| import networkx as nx | import networkx as nx | ||||
| from six.moves import map | |||||
| from six.moves import zip | |||||
| raussendorf_unit_cell = ( | raussendorf_unit_cell = ( | ||||
| ((1, 0, 0), (1, 1, 0)), ((0, 1, 0), (1, 1, 0)), | ((1, 0, 0), (1, 1, 0)), ((0, 1, 0), (1, 1, 0)), | ||||
| @@ -1,6 +1,7 @@ | |||||
| import numpy as np | import numpy as np | ||||
| from abp import qi, GraphState | from abp import qi, GraphState | ||||
| import mock | import mock | ||||
| import pytest | |||||
| DEPTH = 1000 | DEPTH = 1000 | ||||
| @@ -125,7 +126,7 @@ def test_against_chp(n=5): | |||||
| try: | try: | ||||
| import chp | import chp | ||||
| except ImportError: | except ImportError: | ||||
| raise nose.SkipTest("CHP is not installed") | |||||
| raise pytest.skip("CHP is not installed") | |||||
| def get_chp_state(): | def get_chp_state(): | ||||
| """ Helper to convert CHP to CircuitModel """ | """ Helper to convert CHP to CircuitModel """ | ||||