ソースを参照

Trying autofinding of global phase

master
Pete Shadbolt 8年前
コミット
02f80e7b97
2個のファイルの変更25行の追加2行の削除
  1. +14
    -2
      abp/make_tables.py
  2. +11
    -0
      tests/test_normalize_global_phase.py

+ 14
- 2
abp/make_tables.py ファイルの表示

@@ -16,6 +16,7 @@ from clifford import decompositions

def find_clifford(needle, haystack):
""" Find the index of a given u within a list of unitaries, up to a global phase """
needle = normalize_global_phase(needle)
for i, t in enumerate(haystack):
for phase in range(8):
if np.allclose(t, np.exp(1j * phase * np.pi / 4.) * needle):
@@ -23,6 +24,16 @@ def find_clifford(needle, haystack):
raise IndexError


def normalize_global_phase(m):
""" Normalize the global phase of a matrix """
f = m.flatten()
v = f[np.flatnonzero(f)[0]]
print v
phase = np.arctan2(v.imag, v.real) % np.pi
rot = np.exp(-1j*phase)
return rot * m if rot * v > 0 else -rot*m


def find_cz(bond, c1, c2, commuters, state_table):
""" Find the output of a CZ operation """
# Figure out the target state
@@ -47,7 +58,8 @@ def find_cz(bond, c1, c2, commuters, state_table):
def compose_u(decomposition):
""" Get the unitary representation of a particular decomposition """
matrices = ({"x": qi.sqx, "z": qi.msqz}[c] for c in decomposition)
return reduce(np.dot, matrices, np.matrix(np.eye(2, dtype=complex)))
output = reduce(np.dot, matrices, np.matrix(np.eye(2, dtype=complex)))
return normalize_global_phase(output)


def get_unitaries():
@@ -79,7 +91,7 @@ def get_state_table(unitaries):
for bond, i, j in tqdm(params, desc="Building state table"):
state = qi.bond if bond else qi.nobond
kp = np.kron(unitaries[i], unitaries[j])
state_table[bond, i, j, :] = np.dot(kp, state).T
state_table[bond, i, j, :] = normalize_global_phase(np.dot(kp, state).T)
return state_table




+ 11
- 0
tests/test_normalize_global_phase.py ファイルの表示

@@ -0,0 +1,11 @@
from abp import make_tables
from abp import qi
import numpy as np

def test_normalize_global_phase():
for i in range(10):
u = qi.pz
phase = np.random.uniform(0, 2*np.pi)
m = np.exp(1j*phase) * u
normalized = make_tables.normalize_global_phase(m)
assert np.allclose(normalized, u)

読み込み中…
キャンセル
保存