@@ -42,6 +42,15 @@ The complete set of aliases for single-qubit Cliffords is as follows: | |||||
from tables import * | from tables import * | ||||
# Aliases | |||||
identity = by_name["identity"] | |||||
hadamard = by_name["hadamard"] | |||||
px = by_name["px"] | |||||
py = by_name["py"] | |||||
pz = by_name["pz"] | |||||
msqx_h = by_name["msqx_h"] | |||||
sqz_h = by_name["sqz_h"] | |||||
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] | ||||
@@ -60,6 +60,6 @@ class GraphState(graphstate.GraphState, nx.Graph): | |||||
""" Automatically add vops if they're not present """ | """ Automatically add vops if they're not present """ | ||||
for key in self.node: | for key in self.node: | ||||
if not "vop" in self.node[key]: | if not "vop" in self.node[key]: | ||||
self.node[key]["vop"] = clifford.by_name["identity"] | |||||
self.node[key]["vop"] = clifford.identity | |||||
@@ -31,7 +31,7 @@ class GraphState(object): | |||||
self.adj = data.adj.copy() | self.adj = data.adj.copy() | ||||
self.node = data.node.copy() | self.node = data.node.copy() | ||||
for key, value in self.node.items(): | for key, value in self.node.items(): | ||||
self.node[key]["vop"] = data.node[key].get("vop", clifford.by_name["identity"]) | |||||
self.node[key]["vop"] = data.node[key].get("vop", clifford.identity) | |||||
except AttributeError: | except AttributeError: | ||||
try: | try: | ||||
# Provided with a list of node names? | # Provided with a list of node names? | ||||
@@ -144,10 +144,10 @@ class GraphState(object): | |||||
self._toggle_edge(i, j) | self._toggle_edge(i, j) | ||||
self.node[v]["vop"] = clifford.times_table[ | self.node[v]["vop"] = clifford.times_table[ | ||||
self.node[v]["vop"], clifford.by_name["msqx_h"]] | |||||
self.node[v]["vop"], clifford.msqx_h] | |||||
for i in self.adj[v]: | for i in self.adj[v]: | ||||
self.node[i]["vop"] = clifford.times_table[ | self.node[i]["vop"] = clifford.times_table[ | ||||
self.node[i]["vop"], clifford.by_name["sqz_h"]] | |||||
self.node[i]["vop"], clifford.sqz_h] | |||||
def act_local_rotation(self, node, operation): | def act_local_rotation(self, node, operation): | ||||
""" Act a local rotation on a qubit | """ Act a local rotation on a qubit | ||||
@@ -229,11 +229,11 @@ class GraphState(object): | |||||
if phase == -1: | if phase == -1: | ||||
result = not result | result = not result | ||||
if basis == clifford.by_name["px"]: | |||||
if basis == clifford.px: | |||||
result, determinate = self._measure_graph_x(node, result) | result, determinate = self._measure_graph_x(node, result) | ||||
elif basis == clifford.by_name["py"]: | |||||
elif basis == clifford.py: | |||||
result, determinate = self._measure_graph_y(node, result) | result, determinate = self._measure_graph_y(node, result) | ||||
elif basis == clifford.by_name["pz"]: | |||||
elif basis == clifford.pz: | |||||
result, determinate = self._measure_graph_z(node, result) | result, determinate = self._measure_graph_z(node, result) | ||||
else: | else: | ||||
raise ValueError("You can only measure in {X,Y,Z}") | raise ValueError("You can only measure in {X,Y,Z}") | ||||
@@ -5,9 +5,9 @@ Implements a simple Stabilizer object. | |||||
import itertools as it | import itertools as it | ||||
from abp import clifford | from abp import clifford | ||||
I = clifford.by_name["identity"] | |||||
X = clifford.by_name["px"] | |||||
Z = clifford.by_name["pz"] | |||||
I = clifford.identity | |||||
X = clifford.px | |||||
Z = clifford.pz | |||||
class Stabilizer(object): | class Stabilizer(object): | ||||
def __init__(self, g): | def __init__(self, g): | ||||
@@ -65,7 +65,7 @@ def test_conjugation_table(): | |||||
def test_cz_table_makes_sense(): | def test_cz_table_makes_sense(): | ||||
""" Test the CZ table is symmetric """ | """ Test the CZ table is symmetric """ | ||||
hadamard = clifford.by_name["hadamard"] | |||||
hadamard = clifford.hadamard | |||||
assert all(clifford.cz_table[0, 0, 0] == [1, 0, 0]) | assert all(clifford.cz_table[0, 0, 0] == [1, 0, 0]) | ||||
assert all(clifford.cz_table[1, 0, 0] == [0, 0, 0]) | assert all(clifford.cz_table[1, 0, 0] == [0, 0, 0]) | ||||
assert all( | assert all( | ||||
@@ -10,9 +10,9 @@ DEPTH = 100 | |||||
def test_initialization(): | def test_initialization(): | ||||
g = GraphState("abc") | g = GraphState("abc") | ||||
assert g.node["a"]["vop"] == clifford.by_name["identity"] | |||||
assert g.node["a"]["vop"] == clifford.identity | |||||
g = GraphState("abc", vop="hadamard") | g = GraphState("abc", vop="hadamard") | ||||
assert g.node["c"]["vop"] == clifford.by_name["hadamard"] | |||||
assert g.node["c"]["vop"] == clifford.hadamard | |||||
g = GraphState(5) | g = GraphState(5) | ||||
assert len(g.node) == 5 | assert len(g.node) == 5 | ||||
@@ -44,13 +44,13 @@ def test_remove_vop(): | |||||
""" Test that removing VOPs really works """ | """ Test that removing VOPs really works """ | ||||
g = mock.simple_graph() | g = mock.simple_graph() | ||||
g.remove_vop(0, 1) | g.remove_vop(0, 1) | ||||
assert g.node[0]["vop"] == clifford.by_name["identity"] | |||||
assert g.node[0]["vop"] == clifford.identity | |||||
g.remove_vop(1, 1) | g.remove_vop(1, 1) | ||||
assert g.node[1]["vop"] == clifford.by_name["identity"] | |||||
assert g.node[1]["vop"] == clifford.identity | |||||
g.remove_vop(2, 1) | g.remove_vop(2, 1) | ||||
assert g.node[2]["vop"] == clifford.by_name["identity"] | |||||
assert g.node[2]["vop"] == clifford.identity | |||||
g.remove_vop(0, 1) | g.remove_vop(0, 1) | ||||
assert g.node[0]["vop"] == clifford.by_name["identity"] | |||||
assert g.node[0]["vop"] == clifford.identity | |||||
def test_edgelist(): | def test_edgelist(): | ||||
@@ -75,9 +75,9 @@ def test_stress(n=int(1e5)): | |||||
def test_cz(): | def test_cz(): | ||||
""" Test CZ gate """ | """ Test CZ gate """ | ||||
g = GraphState([0, 1], vop="hadamard") | g = GraphState([0, 1], vop="hadamard") | ||||
g.act_local_rotation(0, clifford.by_name["hadamard"]) | |||||
g.act_local_rotation(1, clifford.by_name["hadamard"]) | |||||
g.act_local_rotation(1, clifford.by_name["py"]) | |||||
g.act_local_rotation(0, clifford.hadamard) | |||||
g.act_local_rotation(1, clifford.hadamard) | |||||
g.act_local_rotation(1, clifford.py) | |||||
assert not g.has_edge(0, 1) | assert not g.has_edge(0, 1) | ||||
g.act_cz(0, 1) | g.act_cz(0, 1) | ||||
assert g.has_edge(0, 1) | assert g.has_edge(0, 1) | ||||