From ec23365183f2f86024b9d4fe62744950a6ef6c67 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Thu, 17 Nov 2016 20:47:41 -0800 Subject: [PATCH] Finish updating docs, add Stabilizer.__getitem__ --- abp/stabilizer.py | 4 ++++ doc/index.rst | 32 ++++++++++++++++++++++++++++---- tests/test_stabilizer.py | 3 +++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/abp/stabilizer.py b/abp/stabilizer.py index 0f26da7..236ce35 100644 --- a/abp/stabilizer.py +++ b/abp/stabilizer.py @@ -33,6 +33,10 @@ class Stabilizer(object): return {"paulis": self.tableau, "phases": {key: m[value] for key, value in self.phases.items()}} + def __getitem__(self, (i, j)): + """" Pass straight through to the dictionary """ + return self.tableau[i][j] + def __str__(self): """ Represent as a string """ keys = map(str, self.tableau.keys()) diff --git a/doc/index.rst b/doc/index.rst index 6652b2e..3226081 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -78,7 +78,7 @@ Or look directly at the vertex operators and neighbour lists: 1: IA - 2: IA - -This representation might be unfamiliar. Each row shows the index of the qubit, then the _vertex operator_, then a list of neighbouring qubits. To understand vertex operators, read the original paper by Anders and Briegel. +This representation might be unfamiliar. Each row shows the index of the qubit, then the **vertex operator**, then a list of neighbouring qubits. To understand vertex operators, read the original paper by Anders and Briegel. Let's act a Hadamard gate on the zeroth qubit -- this will evolve qubit ``0`` to the :math:`H|+\rangle = |1\rangle` state: @@ -88,7 +88,6 @@ Let's act a Hadamard gate on the zeroth qubit -- this will evolve qubit ``0`` to |010❭: √1/4 + i √0 |001❭: √1/4 + i √0 |011❭: √1/4 + i √0 - >>> print g 0: YC - 1: IA - @@ -102,7 +101,6 @@ And now run some CZ gates: 0: YC - 1: IA (2,) 2: IA (1,) - >>> print g.to_state_vector() |000❭: √1/4 + i √0 |010❭: √1/4 + i √0 @@ -117,9 +115,35 @@ Tidy up a bit: |00❭: √1/2 + i √0 |11❭: √1/2 + i √0 -Cool, we made a Bell state. Incidentally, those those state vectors and stabilizers are real objects with methods, not just string-like representations of the state: +Cool, we made a Bell state. Incidentally, those those state vectors and stabilizers are genuine Python objects, not just stringy representations of the state: + >>> g = abp.GraphState(2) + >>> g.act_cz(0, 1) + >>> g.act_hadamard(0) + >>> psi = g.to_state_vector() + >>> print psi + |00❭: √1/2 + i √0 + |11❭: √1/2 + i √0 +``psi`` is a state vector -- i.e. it is an exponentially large vector of complex numbers. We can still run gates on it: + + >>> psi.act_cnot(0, 1) + >>> psi.act_hadamard(0) + >>> print psi + |00❭: √1 + i √0 + +But these operations will be very slow. Let's have a look at the stabilizer tableau: + + >>> tab = g.to_stabilizer() + >>> print tab + 0 1 + ------ + Z Z + X X + >>> print tab.tableau + {0: {0: 3, 1: 3}, 1: {0: 1, 1: 1}} + >>> print tab[0, 0] + 3 GraphState API diff --git a/tests/test_stabilizer.py b/tests/test_stabilizer.py index 4d97b0d..1d5fca8 100644 --- a/tests/test_stabilizer.py +++ b/tests/test_stabilizer.py @@ -19,3 +19,6 @@ def test_stabilizers_against_anders_and_briegel(n=10): assert da == db +def test_stabilizer_access(): + g = GraphState(3) + print g.to_stabilizer()[0, 0]