소스 검색

Test passing

master
Pete Shadbolt 7 년 전
부모
커밋
2698308d49
11개의 변경된 파일77개의 추가작업 그리고 66개의 파일을 삭제
  1. +1
    -1
      abp/clifford.py
  2. +1
    -1
      abp/graphstate.py
  3. +54
    -0
      tests/ab.py
  4. +4
    -45
      tests/mock.py
  5. +9
    -7
      tests/test_against_anders_and_briegel.py
  6. +1
    -2
      tests/test_graphstate.py
  7. +1
    -2
      tests/test_json.py
  8. +1
    -2
      tests/test_mercedes.py
  9. +1
    -2
      tests/test_nx.py
  10. +1
    -2
      tests/test_qi.py
  11. +3
    -2
      tests/test_stabilizer.py

+ 1
- 1
abp/clifford.py 파일 보기

@@ -40,7 +40,7 @@ The complete set of aliases for single-qubit Cliffords is as follows:

"""

from .tables import *
from tables import *

# Aliases
identity = by_name["identity"]


+ 1
- 1
abp/graphstate.py 파일 보기

@@ -108,7 +108,7 @@ class GraphState(object):
>>> g.act_circuit([("hadamard", 0), ("hadamard", 1), ("cz", (0, 1))])

"""
for operation, node in circuit:
for node, operation in circuit:
if operation == "cz":
self.act_cz(*node)
else:


+ 54
- 0
tests/ab.py 파일 보기

@@ -0,0 +1,54 @@
"""
Mock graphs used for testing
"""

import numpy as np
import abp
from abp import GraphState, clifford, qi
from numpy import random
import pytest
from anders_briegel import graphsim

# We always run with A&B's CZ table when we are testing
clifford.use_old_cz()


class AndersWrapper(graphsim.GraphRegister):

""" A wrapper for A&B to make the interface identical and enable equality testing """

def __init__(self, nodes):
assert list(nodes) == list(range(len(nodes)))
super(AndersWrapper, self).__init__(len(nodes))

def act_local_rotation(self, qubit, operation):
operation = clifford.by_name[str(operation)]
op = graphsim.LocCliffOp(operation)
super(AndersWrapper, self).local_op(qubit, op)

def act_cz(self, a, b):
super(AndersWrapper, self).cphase(a, b)

def measure(self, qubit, basis, force):
basis = {1: graphsim.lco_X,
2: graphsim.lco_Y,
3: graphsim.lco_Z}[clifford.by_name[str(basis)]]
return super(AndersWrapper, self).measure(qubit, basis, None, force)

def __eq__(self, other):
return self.to_json() == other.to_json()

def act_circuit(self, circuit):
for operation, node in circuit:
if operation == "cz":
self.act_cz(*node)
else:
self.act_local_rotation(node, operation)


def test_circuit(circuit, n):
""" Check that two classes exhibit the same behaviour for a given circuit """
a = circuit_to_state(ABPWrapper, n, circuit)
b = circuit_to_state(AndersWrapper, n, circuit)
assert a == b


+ 4
- 45
tests/mock.py 파일 보기

@@ -7,45 +7,10 @@ import abp
from abp import GraphState, clifford, qi
from numpy import random
import pytest
from anders_briegel import graphsim

# We always run with A&B's CZ table when we are testing
clifford.use_old_cz()


class AndersWrapper(graphsim.GraphRegister):

""" A wrapper for A&B to make the interface identical and enable equality testing """

def __init__(self, nodes):
assert list(nodes) == list(range(len(nodes)))
super(AndersWrapper, self).__init__(len(nodes))

def act_local_rotation(self, qubit, operation):
operation = clifford.by_name[str(operation)]
op = graphsim.LocCliffOp(operation)
super(AndersWrapper, self).local_op(qubit, op)

def act_cz(self, a, b):
super(AndersWrapper, self).cphase(a, b)

def measure(self, qubit, basis, force):
basis = {1: graphsim.lco_X,
2: graphsim.lco_Y,
3: graphsim.lco_Z}[clifford.by_name[str(basis)]]
return super(AndersWrapper, self).measure(qubit, basis, None, force)

def __eq__(self, other):
return self.to_json() == other.to_json()

def act_circuit(self, circuit):
for operation, node in circuit:
if operation == "cz":
self.act_cz(*node)
else:
self.act_local_rotation(node, operation)


class ABPWrapper(GraphState):

""" A wrapper for abp, just to ensure determinism """
@@ -103,8 +68,8 @@ def named_node_graph():
""" A graph with named nodes"""
edges = (0, 1), (1, 2), (2, 0), (0, 3), (100, 200), (200, "named")
g = ABPWrapper([0, 1, 2, 3, 100, 200, "named"])
g.act_circuit(("hadamard", i) for i in g.node)
g.act_circuit(("cz", edge) for edge in edges)
g.act_circuit((i, "hadamard") for i in g.node)
g.act_circuit((edge, "cz") for edge in edges)
return g


@@ -112,8 +77,8 @@ def simple_graph():
""" A simple graph to test with"""
edges = (0, 1), (1, 2), (2, 0), (0, 3), (100, 200)
g = ABPWrapper([0, 1, 2, 3, 100, 200])
g.act_circuit(("hadamard", i) for i in g.node)
g.act_circuit(("cz", edge) for edge in edges)
g.act_circuit((i, "hadamard") for i in g.node)
g.act_circuit((edge, "cz") for edge in edges)
return g


@@ -124,12 +89,6 @@ def circuit_to_state(Base, n, circuit):
return g


def test_circuit(circuit, n):
""" Check that two classes exhibit the same behaviour for a given circuit """
a = circuit_to_state(ABPWrapper, n, circuit)
b = circuit_to_state(AndersWrapper, n, circuit)
assert a == b


if __name__ == '__main__':
for i in range(1000):


+ 9
- 7
tests/test_against_anders_and_briegel.py 파일 보기

@@ -3,7 +3,9 @@ import numpy as np
from numpy import random
import itertools as it
import pytest
mock = pytest.importorskip("mock")
import mock
ab = pytest.importorskip("ab")


REPEATS = 100
DEPTH = 100
@@ -12,28 +14,28 @@ PAULIS = ("px", "py", "pz")
def test_hadamard():
""" Test hadamards """
circuit = [(0, "hadamard")]
mock.test_circuit(circuit, 1)
ab.test_circuit(circuit, 1)


def test_local_rotations():
""" Test local rotations """
for i in list(range(REPEATS)):
circuit = [(0, random.choice(list(range(24)))) for j in range(DEPTH)]
mock.test_circuit(circuit, 1)
ab.test_circuit(circuit, 1)


def test_times_table():
""" Test times table """
for i, j in it.product(list(range(24)), list(range(24))):
circuit = [(0, i), (0, j)]
mock.test_circuit(circuit, 1)
ab.test_circuit(circuit, 1)


def test_cz_table():
""" Test the CZ table """
for i, j in it.product(list(range(24)), list(range(24))):
circuit = [(0, i), (1, j), ((0, 1), "cz")]
mock.test_circuit(circuit, 2)
ab.test_circuit(circuit, 2)


def test_cz_hadamard(n=10):
@@ -43,7 +45,7 @@ def test_cz_hadamard(n=10):
circuit = [(mock.random_pair(n), gate) if gate == "cz"
else (random.choice(list(range(n))), gate)
for gate in circuit]
mock.test_circuit(circuit, n)
ab.test_circuit(circuit, n)


def test_all(n=10):
@@ -53,7 +55,7 @@ def test_all(n=10):
circuit = [(mock.random_pair(n), gate) if gate == "cz"
else (random.choice(list(range(n))), gate)
for gate in circuit]
mock.test_circuit(circuit, n)
ab.test_circuit(circuit, n)


def test_single_qubit_measurement():


+ 1
- 2
tests/test_graphstate.py 파일 보기

@@ -2,8 +2,7 @@ from abp import GraphState, CircuitModel, clifford
import random
import numpy as np
import networkx as nx
import pytest
mock = pytest.importorskip("mock")
import mock

REPEATS = 100
DEPTH = 100


+ 1
- 2
tests/test_json.py 파일 보기

@@ -1,6 +1,5 @@
import abp
import pytest
mock = pytest.importorskip("mock")
import mock

def test_json():
""" Test to_json and from_json """


+ 1
- 2
tests/test_mercedes.py 파일 보기

@@ -1,7 +1,6 @@
from abp import GraphState
from abp.util import xyz
import pytest
mock = pytest.importorskip("mock")
import mock

def linear_cluster(n):
g = GraphState(list(range(n)), vop="hadamard")


+ 1
- 2
tests/test_nx.py 파일 보기

@@ -3,8 +3,7 @@ import networkx as nx
from abp import GraphState, NXGraphState
from abp import clifford
from abp.util import xyz
import pytest
mock = pytest.importorskip("mock")
import mock


def test_json_basic():


+ 1
- 2
tests/test_qi.py 파일 보기

@@ -1,7 +1,6 @@
import numpy as np
from abp import qi, GraphState
import pytest
mock = pytest.importorskip("mock")
import mock

DEPTH = 1000



+ 3
- 2
tests/test_stabilizer.py 파일 보기

@@ -1,6 +1,7 @@
from abp import GraphState
import mock
import pytest
mock = pytest.importorskip("mock")
ab = pytest.importorskip("ab")

REPEATS = 1000

@@ -9,7 +10,7 @@ def test_stabilizers_against_anders_and_briegel(n=10):
for i in list(range(REPEATS)):
c = mock.random_stabilizer_circuit(n)
g = mock.AndersWrapper(list(range(n)))
g = ab.AndersWrapper(list(range(n)))
g.act_circuit(c)
da = g.get_full_stabilizer().to_dictionary()



불러오는 중...
취소
저장