def main(): # Create evaluation and interpolation points p = 4 # order x = np.linspace(-1, 1, 100) xi = quad.GaussLegendreLobatto(p).x # Create shape functions shape = shp.Lagrange(x, xi) print(shape) # Store and plot if parse().gui: import matplotlib.pyplot as plt l = np.zeros((shape.n, len(x))) dl = np.zeros((shape.n, len(x))) for k in range(len(x)): l[:, k] = np.transpose(shape.sf[k]) dl[:, k] = shape.dsf[k] plt.figure(1) for i in range(shape.n): plt.plot(x, l[i, :]) plt.plot(xi[i], 0, 'ko') plt.xlabel('x') plt.ylabel('N_i') plt.title('Shape functions of order {:d}'.format(p)) plt.figure(2) for i in range(shape.n): plt.plot(x, dl[i, :]) plt.plot(xi[i], 0, 'ko') plt.xlabel('x') plt.ylabel('dN_i/dx') plt.title('Shape function derivatives of order {:d}'.format(p)) plt.show()
def test_parse_one_qubit(tmpdir): p = tmpdir.join('parse.qsel') p.write('superposition superposition superposition superposition\n' 'superposition entanglement superposition superposition') all_qubits, program = run.parse(str(p)) assert all_qubits == set([0]) assert program == [{ 'gate': 'H', 'qubits': [0] }, { 'gate': 'M', 'qubits': [0] }]
def test_valid_place_cmd(self): (cmd, args) = parse('PLACE 1,2,NORTH\n') assert cmd == 'PLACE' assert args['x'] == 1 assert args['y'] == 2 assert args['f'] == 'NORTH'
def test_valid_report_cmd(self): (cmd, args) = parse('REPORT\n') assert cmd == 'REPORT' assert args == None
def test_valid_right_cmd(self): (cmd, args) = parse('RIGHT\n') assert cmd == 'RIGHT' assert args == None
def test_valid_left_cmd(self): (cmd, args) = parse('LEFT\n') assert cmd == 'LEFT' assert args == None
def test_valid_move_cmd(self): (cmd, args) = parse('MOVE\n') assert cmd == 'MOVE' assert args == None
#!/usr/bin/env python2 import datetime import nose.tools as n from run import parse observed_data = parse(open('test.xml').read()) expected_data = [ { 'page': 7, 'within_page': 1, 'id': '8541981221', 'owner': '63130627@N07', 'title': 'Aurora_Coming @^_^@!', 'dateadded': datetime.datetime.fromtimestamp(1362860132), datetaken DATETIME NOT NULL, description TEXT NOT NULL, url_l TEXT NOT NULL, longitude REAL NOT NULL, latitude REAL NOT NULL, }, { 'page': 7, 'within_page': 2, 'id': '8541904081', 'owner': '63130627@N07', 'title': 'Aurora_Dancing @ Iceland', 'dateadded': datetime.datetime.fromtimestamp(1362858321), }, { 'page': 7, 'within_page': 3, 'id': '8541845647', 'owner': '35612079@N08',
def test_parse_m_wrong_qubit_number(tmpdir): p = tmpdir.join('parse.qsel') p.write(' '.join([run.S, run.E, run.S, run.S, run.S, run.E, run.E, run.E])) with pytest.raises(SyntaxError, match='M gate'): run.parse(str(p))
def test_parse_bad_tokens(tmpdir): p = tmpdir.join('parse.qsel') p.write('entanglement x') with pytest.raises(SyntaxError, match='Only'): run.parse(str(p))
def test_parse_too_few_qubits(tmpdir): p = tmpdir.join('parse.qsel') p.write('entanglement entanglement superposition') with pytest.raises(SyntaxError, match='Not enough'): run.parse(str(p))