瀏覽代碼

Finish updating docs, add Stabilizer.__getitem__

master
Pete Shadbolt 8 年之前
父節點
當前提交
ec23365183
共有 3 個文件被更改,包括 35 次插入4 次删除
  1. +4
    -0
      abp/stabilizer.py
  2. +28
    -4
      doc/index.rst
  3. +3
    -0
      tests/test_stabilizer.py

+ 4
- 0
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())


+ 28
- 4
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


+ 3
- 0
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]

Loading…
取消
儲存