Bladeren bron

Split tests

master
Pete Shadbolt 8 jaren geleden
bovenliggende
commit
b43a7499d7
2 gewijzigde bestanden met toevoegingen van 29 en 4 verwijderingen
  1. +1
    -1
      abp/qi.py
  2. +28
    -3
      tests/test_against_circuit_model.py

+ 1
- 1
abp/qi.py Bestand weergeven

@@ -80,7 +80,7 @@ class CircuitModel(object):
output = np.zeros((self.d, 1), dtype=complex)
for i, v in enumerate(self.state):
q = i & where > 0
output[i] += v*u[q, q]
output[i] += v*u[q, q] # TODO this is probably wrong
output[i ^ where] += v*u[not q, q]
self.state = output



+ 28
- 3
tests/test_against_circuit_model.py Bestand weergeven

@@ -4,9 +4,9 @@ from abp import clifford
import numpy as np
import random

def multi_qubit_test():
""" A multi qubit test """
n = 6
def test_hadamard_only_multiqubit():
""" A multi qubit test with Hadamards only"""
n = 4
g = GraphState(range(n))
c = CircuitModel(n)

@@ -27,3 +27,28 @@ def multi_qubit_test():
assert np.allclose(s1, s2)


def test_all_multiqubit():
""" A multi qubit test with arbitrary local rotations """
n = 4
g = GraphState(range(n))
c = CircuitModel(n)

for i in range(10):
i = np.random.randint(0, n-1)
j = np.random.randint(0, 24)
print i, j
g.act_local_rotation(i, j)
c.act_local_rotation(i, clifford.unitaries[j])

assert np.allclose(g.to_state_vector().state, c.state)

#for i in range(100):
#a, b = np.random.randint(0, n-1, 2)
#if a != b:
#g.act_cz(a, b)
#c.act_cz(a, b)

#s1 = clifford.normalize_global_phase(g.to_state_vector().state)
#s2 = clifford.normalize_global_phase(c.state)
#assert np.allclose(s1, s2)


Laden…
Annuleren
Opslaan