Przeglądaj źródła

JS tests, remove visible graph state

master
Pete Shadbolt 8 lat temu
rodzic
commit
7024c849d0
11 zmienionych plików z 366 dodań i 36 usunięć
  1. +0
    -1
      abp/clifford.py
  2. +33
    -1
      abp/graphstate.py
  3. +0
    -29
      abp/viz.py
  4. +2
    -2
      examples/lattice_demo.py
  5. +1
    -0
      static/scripts/.gitignore
  6. +2
    -0
      static/scripts/anders_briegel.js
  7. +2
    -1
      static/scripts/tables.js
  8. +4
    -0
      static/scripts/tests.js
  9. +299
    -0
      static/test.css
  10. +23
    -0
      static/test.html
  11. +0
    -2
      tests/test_nxgraphstate.py

+ 0
- 1
abp/clifford.py Wyświetl plik

@@ -105,7 +105,6 @@ def get_cz_table(unitaries):
""" Compute the lookup table for the CZ (A&B eq. 9) """
# Get a cached state table and a list of gates which commute with CZ
commuters = get_commuters(unitaries)
print commuters
state_table = get_state_table(unitaries)

# And now build the CZ table


+ 33
- 1
abp/graphstate.py Wyświetl plik

@@ -10,12 +10,20 @@ try:
from networkx import Graph as NXGraph
except ImportError:
NXGraph = object
try:
import websocket
from socket import error as socket_error
import time, atexit
except ImportError:
websocket = None

class GraphState(NXGraph):

def __init__(self, nodes=[]):
def __init__(self, nodes=[], connect_to_server=True):
self.adj, self.node = {}, {}
self.add_nodes(nodes)
if connect_to_server:
self.connect_to_server()

def add_node(self, v, **kwargs):
""" Add a node """
@@ -198,3 +206,27 @@ class GraphState(NXGraph):
""" Check equality between graphs """
return self.adj == other.adj and self.node == other.node

def connect_to_server(self, uri = "ws://localhost:5000"):
""" Attempt to connect to the websocket server """
if not websocket:
return
try:
self.ws = websocket.create_connection(uri)
atexit.register(self.shutdown)
except socket_error:
#print "Could not establish connection to server ({}).".format(uri)
self.ws = None


def shutdown(self):
""" Close the connection to the websocket """
self.update()
self.ws.close()

def update(self, delay = 0.5):
""" Call this function when you are ready to send data to the browser """
if not self.ws:
return
data = json.dumps(self.to_json())
self.ws.send(data)
time.sleep(delay)

+ 0
- 29
abp/viz.py Wyświetl plik

@@ -1,29 +0,0 @@
"""
Allows us to visualize the state in a browser
"""

import atexit, json, time
from graphstate import GraphState
from websocket import create_connection

class VisibleGraphState(GraphState):

""" Overloads the graph state with methods for sending to the browser over a websocket """

def __init__(self, *args, **kwargs):
""" Constructor """
GraphState.__init__(self, *args, **kwargs)
self.ws = create_connection("ws://localhost:5000")
atexit.register(self.shutdown)

def shutdown(self):
""" The client should shut down automatically on close """
self.update()
self.ws.close()

def update(self, delay = 0.5):
""" Call this function when you are ready to send data to the browser """
data = json.dumps(self.to_json())
self.ws.send(data)
time.sleep(delay)


+ 2
- 2
examples/lattice_demo.py Wyświetl plik

@@ -1,4 +1,4 @@
from abp.viz import VisibleGraphState
from abp.graphstate import GraphState
from abp.util import xyz
import numpy as np
import time
@@ -32,7 +32,7 @@ def lattice(unit_cell, size):
# s = VisibleGraphState()
nodes, edges = lattice(square_unit_cell, (4, 4))

psi = VisibleGraphState()
psi = GraphState()
for node in nodes:
psi.add_node(str(node), position=xyz(node[0], node[1]))
psi.act_hadamard(str(node))


+ 1
- 0
static/scripts/.gitignore Wyświetl plik

@@ -0,0 +1 @@
qcengine

+ 2
- 0
static/scripts/anders_briegel.js Wyświetl plik

@@ -3,6 +3,7 @@ abj.node = {};
abj.adj = {};

abj.add_node = function(node, meta) {
if (meta === undefined){meta = {};}
abj.adj[node] = {};
abj.node[node] = {};
abj.node[node].vop = tables.clifford.hadamard;
@@ -143,3 +144,4 @@ abj.order = function(){
return Object.keys(abj.node).length;
};



+ 2
- 1
static/scripts/tables.js
Plik diff jest za duży
Wyświetl plik


+ 4
- 0
static/scripts/tests.js Wyświetl plik

@@ -0,0 +1,4 @@
QUnit.test( "Adding nodes", function( assert ) {
abj.add_node(0);
assert.ok(abj.node[0].vop === 10, JSON.stringify(abj.node));
});

+ 299
- 0
static/test.css Wyświetl plik

@@ -0,0 +1,299 @@
/*!
* QUnit 1.23.1
* https://qunitjs.com/
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2016-04-12T17:29Z
*/

/** Font Family and Sizes */

#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}

#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }


/** Resets */

#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}


/** Header */

#qunit-header {
padding: 0.5em 0 0.5em 1em;

color: #FFFFFF;
background-color: #000000;

font-size: 1.5em;
line-height: 1em;
font-weight: 400;

}

#qunit-header a {
text-decoration: none;
color: #FFFFFF;
}

#qunit-header a:hover,
#qunit-header a:focus {
color: #FFF;
}

#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 0.5em 0 0.1em;
}

#qunit-banner {
height: 5px;
}

#qunit-testrunner-toolbar {
padding: 0.5em 1em 0.5em 1em;
color: #5E740B;
background-color: #EEE;
overflow: hidden;
}

#qunit-filteredTest {
padding: 0.5em 1em 0.5em 1em;
background-color: #F4FF77;
color: #366097;
}

#qunit-userAgent {
padding: 0.5em 1em 0.5em 1em;
background-color: #000000;
color: #FFF;
}

#qunit-modulefilter-container {
float: right;
padding: 0.2em;
}

.qunit-url-config {
display: inline-block;
padding: 0.1em;
}

.qunit-filter {
display: block;
float: right;
margin-left: 1em;
}

/** Tests: Pass/Fail */

#qunit-tests {
list-style-position: inside;
}

#qunit-tests li {
padding: 0.4em 1em 0.4em 1em;
border-bottom: 1px solid #FFF;
list-style-position: inside;
}

#qunit-tests > li {
display: none;
}

#qunit-tests li.running,
#qunit-tests li.pass,
#qunit-tests li.fail,
#qunit-tests li.skipped {
display: list-item;
}

#qunit-tests.hidepass {
position: relative;
}

#qunit-tests.hidepass li.running,
#qunit-tests.hidepass li.pass {
visibility: hidden;
position: absolute;
width: 0;
height: 0;
padding: 0;
border: 0;
margin: 0;
}

#qunit-tests li strong {
cursor: pointer;
}

#qunit-tests li.skipped strong {
cursor: default;
}

#qunit-tests li a {
padding: 0.5em;
color: #C2CCD1;
text-decoration: none;
}

#qunit-tests li p a {
padding: 0.25em;
color: #6B6464;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}

#qunit-tests li .runtime {
float: right;
font-size: smaller;
}

.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;

background-color: #FFF;

}

.qunit-source {
margin: 0.6em 0 0.3em;
}

.qunit-collapsed {
display: none;
}

#qunit-tests table {
border-collapse: collapse;
margin-top: 0.2em;
}

#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 0.5em 0 0;
}

#qunit-tests td {
vertical-align: top;
}

#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}

#qunit-tests del {
background-color: #E0F2BE;
color: #374E0C;
text-decoration: none;
}

#qunit-tests ins {
background-color: #FFCACA;
color: #500;
text-decoration: none;
}

/*** Test Counts */

#qunit-tests b.counts { color: #000; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }

#qunit-tests li li {
padding: 5px;
background-color: #FFF;
border-bottom: none;
list-style-position: inside;
}

/*** Passing Styles */

#qunit-tests li li.pass {
color: #3C510C;
background-color: #FFF;
border-left: 10px solid #C6E746;
}

#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }

#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999; }

#qunit-banner.qunit-pass { background-color: #C6E746; }

/*** Failing Styles */

#qunit-tests li li.fail {
color: #710909;
background-color: #FFF;
border-left: 10px solid #EE5757;
white-space: pre;
}


#qunit-tests .fail { color: #000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000; }

#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: #008000; }

#qunit-banner.qunit-fail { background-color: #EE5757; }

/*** Skipped tests */

#qunit-tests .skipped {
background-color: #EBECE9;
}

#qunit-tests .qunit-skipped-label {
background-color: #F4FF77;
display: inline-block;
font-style: normal;
color: #366097;
line-height: 1.8em;
padding: 0 0.5em;
margin: -0.4em 0.4em -0.4em 0;
}

/** Result */

#qunit-testresult {
padding: 0.5em 1em 0.5em 1em;

color: #2B81AF;
background-color: #D2E0E6;

border-bottom: 1px solid #FFF;
}
#qunit-testresult .module-name {
font-weight: 700;
}

/** Fixture */

#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}

+ 23
- 0
static/test.html Wyświetl plik

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Testing A&B</title>
<link rel="stylesheet" href="test.css">
</head>
<body>
<script src="scripts/qcengine/qcengine_bitfield.js"></script>
<script src="scripts/qcengine/qcengine_reg.js"></script>
<script src="scripts/qcengine/qcengine_int.js"></script>
<script src="scripts/qcengine/qcengine_basicops.js"></script>
<script src="scripts/qcengine/qcengine_setup.js"></script>
<script src="scripts/tables.js"></script>
<script src="scripts/anders_briegel.js"></script>

<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-1.23.1.js"></script>
<script src="scripts/tests.js"></script>
</body>
</html>

+ 0
- 2
tests/test_nxgraphstate.py Wyświetl plik

@@ -9,6 +9,4 @@ def simple_test():
g.act_hadamard(0)
g.act_hadamard(1)
g.act_cz(0, 1)
print g.node[0]["position"]
print nx.to_edgelist(g)


Ładowanie…
Anuluj
Zapisz