Просмотр исходного кода

Add examples/visualization/auto_layout.py

master
Pete Shadbolt 8 лет назад
Родитель
Сommit
75730f954b
3 измененных файлов: 54 добавлений и 6 удалений
  1. +0
    -3
      abp/graphstate.py
  2. +53
    -0
      examples/visualization/auto_layout.py
  3. +1
    -3
      examples/visualization/lattice_3d.py

+ 0
- 3
abp/graphstate.py Просмотреть файл

@@ -383,9 +383,6 @@ class GraphState(object):
|00000>: 0.18+0.00j
|00001>: 0.18+0.00j ...

.. todo::
Doesn't work with non-``int`` node labels

"""
if len(self.node) > 15:
raise ValueError("Cannot build state vector: too many qubits")


+ 53
- 0
examples/visualization/auto_layout.py Просмотреть файл

@@ -0,0 +1,53 @@
from abp.fancy import GraphState
from abp.util import xyz
import numpy as np
import time
import itertools
import networkx as nx

threedee_unit_cell = (
(( 0, 0, 0), (0, 1, 0)),
(( 0, 0, 0), (1, 0, 0)),
(( 1, 0, 0), (1, 1, 0)),
(( 0, 1, 0), (1, 1, 0)),

(( 0, 0, 1), (0, 1, 1)),
(( 0, 0, 1), (1, 0, 1)),
(( 1, 0, 1), (1, 1, 1)),
(( 0, 1, 1), (1, 1, 1)),

(( 0, 0, 0), (0, 0, 1)),
(( 0, 1, 0), (0, 1, 1)),
(( 1, 0, 0), (1, 0, 1)),
(( 1, 1, 0), (1, 1, 1))
)

def add_offset(vector, offset):
""" Offset a vector in n-dimensional space """
return tuple(v + o for v, o in zip(vector, offset))


def offset_unit_cell(unit_cell, offset):
""" Offset a unit cell """
return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}


def lattice(unit_cell, size):
""" Generate a lattice from a unit cell """
edges = set()
for offset in itertools.product(*map(range, size)):
edges |= offset_unit_cell(unit_cell, offset)

nodes = set(itertools.chain(*edges))
return nodes, edges

nodes, edges = lattice(threedee_unit_cell, (3, 3, 3))

psi = GraphState()
for node in nodes:
psi.add_node(str(node))
psi.act_hadamard(str(node))

for edge in edges:
psi.act_cz(str(edge[0]), str(edge[1]))


+ 1
- 3
examples/visualization/lattice_3d.py Просмотреть файл

@@ -41,7 +41,7 @@ def lattice(unit_cell, size):
nodes = set(itertools.chain(*edges))
return nodes, edges

nodes, edges = lattice(threedee_unit_cell, (6, 6, 6))
nodes, edges = lattice(threedee_unit_cell, (3, 3, 3))

psi = GraphState()
for node in nodes:
@@ -51,5 +51,3 @@ for node in nodes:
for edge in edges:
psi.act_cz(str(edge[0]), str(edge[1]))

#print psi.to_state_vector()


Загрузка…
Отмена
Сохранить