Przeglądaj źródła

Gonna go to new clifford definitions

master
Pete Shadbolt 8 lat temu
rodzic
commit
60f1b0cb85
3 zmienionych plików z 53 dodań i 8 usunięć
  1. +44
    -0
      clifford2.py
  2. +5
    -3
      cz.py
  3. +4
    -5
      tests/test_clifford.py

+ 44
- 0
clifford2.py Wyświetl plik

@@ -0,0 +1,44 @@
import numpy as np
from tqdm import tqdm
import os
from qi import *
import cPickle

def find_up_to_phase(u):
""" Find the index of a given u within a list of unitaries, up to a global phase """
global unitaries
for i, t in enumerate(unitaries):
for phase in range(8):
if np.allclose(t, np.exp(1j*phase*np.pi/4.)*u):
return i, phase
raise IndexError


def compose_u(decomposition):
""" Get the unitary representation of a particular decomposition """
us = (elements[c] for c in decomposition)
return np.matrix(reduce(np.dot, us), dtype=complex)


def construct_tables():
""" Constructs multiplication and conjugation tables """
conjugation_table = [find_up_to_phase(u.H)[0] for i, u in enumerate(unitaries)]
times_table = [[find_up_to_phase(u*v)[0] for v in unitaries]
for u in tqdm(unitaries, "Building times-table")]
with open("tables.pkl", "w") as f:
cPickle.dump((conjugation_table, times_table), f)


decompositions = \
("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
"xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
"zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")
elements = {"x": sqx, "z": msqz}
unitaries = [compose_u(d) for d in decompositions]

# Build / reload lookup tables
if not os.path.exists("tables.pkl"):
construct_tables()

if __name__ == '__main__':
pass

+ 5
- 3
cz.py Wyświetl plik

@@ -2,11 +2,13 @@ from matplotlib import pyplot as plt
from graph import *
from viz import draw

def local_complementation(g, vops, a):
for i in g[a]:
for j in g[a]:
def local_complementation(g, vops, v):
for i in g[v]:
for j in g[v]:
if i<j:
toggle_edge(g, i, j)
# vops[i] = times_table[vop[i]][sqrtmiz]
# vops[v] = times_table[vop[v]][sqrtix]

if __name__ == '__main__':
g, vops = graph(10)


+ 4
- 5
tests/test_clifford.py Wyświetl plik

@@ -3,7 +3,7 @@ from numpy import *
from scipy.linalg import sqrtm
from qi import *
from tqdm import tqdm
import itertools as it


def identify_pauli(m):
@@ -45,10 +45,9 @@ def test_we_have_all_useful_gates():
def test_group():
""" Test we are really in a group """
matches = set()
for a in tqdm(lc.unitaries, "Testing this is a group"):
for b in lc.unitaries:
i, phase = lc.find_up_to_phase(a*b)
matches.add(i)
for a, b in tqdm(it.combinations(lc.unitaries, 2), "Testing this is a group"):
i, phase = lc.find_up_to_phase(a*b)
matches.add(i)
assert len(matches)==24




Ładowanie…
Anuluj
Zapisz