Best Python code snippet using localstack_python
test_get_states.py
Source:test_get_states.py
...22 def test_initial_states(self) :23 qregs = new_qregs(self.n_qregs)24 circuit = [I(qreg) for qreg in qregs]25 sim = self.run_sim(circuit, True)26 states = sim.qubits.get_states()27 self.assertEqual(1 + 0j, states[0])28 self.assertTrue(all(states[1:-1] == 0.))29 30 def test_initial_states_with_offset(self) :31 qregs = new_qregs(self.n_qregs)32 circuit = [I(qreg) for qreg in qregs]33 sim = self.run_sim(circuit, True)34 states = sim.qubits.get_states(key = slice(1, None))35 self.assertTrue(all(states[0:-1] == 0.))36 37 def test_x(self) :38 qregs = new_qregs(self.n_qregs)39 circuit = [X(qreg) for qreg in qregs]40 sim = self.run_sim(circuit, True)41 states = sim.qubits.get_states()42 self.assertEqual(1, states[-1])43 self.assertTrue(all(states[0:-2] == 0.))44 45 states = sim.qubits.get_states(key = slice(0, -1))46 self.assertTrue(all(states == 0.))47 state = sim.qubits.get_states(key = -1)48 self.assertEqual(1, state)49 50 def test_h(self) :51 qregs = new_qregs(self.n_qregs)52 circuit = [H(qreg) for qreg in qregs]53 sim = self.run_sim(circuit, True)54 states = sim.qubits.get_states(mathop = qgate.simulator.prob)55 self.assertTrue(np.allclose(1 / len(states), states))56 def test_inversed_range(self) :57 qregs = new_qregs(self.n_qregs)58 circuit = [H(qreg) for qreg in qregs]59 sim = self.run_sim(circuit, False)60 states = sim.qubits.get_states(key = slice(10, 0))61 self.assertEqual(0, len(states))62 states = sim.qubits.get_states(key = slice(10, 0, -1))63 self.assertEqual(10, len(states))64 def test_step(self) :65 qregs = new_qregs(self.n_qregs)66 circuit = [H(qreg) for qreg in qregs]67 sim = self.run_sim(circuit, False)68 states = sim.qubits.get_states()69 states_test = sim.qubits.get_states(key = slice(0, 10, 3))70 self.assertEqual(4, len(states_test))71 states_ref = states[:10:3]72 self.assertTrue(np.allclose(states_ref, states_test))73 74 states_test = sim.qubits.get_states(key = slice(0, 10, 7))75 self.assertEqual(2, len(states_test))76 states_ref = states[:10:7]77 self.assertTrue(np.allclose(states_ref, states_test))78 def test_negative_step(self) :79 qregs = new_qregs(self.n_qregs)80 circuit = [H(qreg) for qreg in qregs]81 sim = self.run_sim(circuit, False)82 states = sim.qubits.get_states()83 states_test = sim.qubits.get_states(key = slice(10, None, -3))84 self.assertEqual(4, len(states_test))85 states_ref = states[10::-3]86 self.assertTrue(np.allclose(states_ref, states_test))87 88 states_test = sim.qubits.get_states(key = slice(10, None, -7))89 self.assertEqual(2, len(states_test))90 states_ref = states[10::-7]91 self.assertTrue(np.allclose(states_ref, states_test))92 93 def test_getter(self) :94 qregs = new_qregs(self.n_qregs)95 circuit = [H(qreg) for qreg in qregs]96 sim = self.run_sim(circuit, True)97 states_getter = sim.qubits.states[:]98 states = sim.qubits.get_states()99 self.assertTrue(np.all(states == states_getter))100 101 states_getter = sim.qubits.states[10:]102 states = sim.qubits.get_states(key=slice(10, None) )103 self.assertTrue(np.all(states == states_getter))104 105 states_getter = sim.qubits.states[:10]106 states = sim.qubits.get_states(key=slice(None, 10))107 self.assertTrue(np.all(states == states_getter))108 109 110 def test_getter_inversed(self) :111 qregs = new_qregs(self.n_qregs)112 circuit = [H(qreg) for qreg in qregs]113 sim = self.run_sim(circuit, True)114 states_getter = sim.qubits.states[::-1]115 states = sim.qubits.get_states()116 states = states[::-1]117 self.assertEqual(len(states), len(states_getter))118 self.assertTrue(np.all(states == states_getter))119 120 states_getter = sim.qubits.states[10::-1]121 states = sim.qubits.get_states(key=slice(0, 12))122 states = states[-1:0:-1]123 self.assertEqual(len(states), len(states_getter))124 self.assertTrue(np.all(states == states_getter))125 126 states_getter = sim.qubits.states[-1:10:-1]127 states = sim.qubits.get_states(key=slice(10, None))128 states = states[-1:0:-1]129 #self.assertTrue(np.all(states == states_getter))130 131 def test_prob_getter(self) :132 qregs = new_qregs(self.n_qregs)133 circuit = [H(qreg) for qreg in qregs]134 sim = self.run_sim(circuit, True)135 states_getter = sim.qubits.prob[:]136 states = sim.qubits.get_states(qgate.simulator.prob)137 self.assertTrue(np.all(states == states_getter))138 139 states_getter = sim.qubits.prob[10:]140 states = sim.qubits.get_states(qgate.simulator.prob, key=slice(10, None))141 self.assertTrue(np.all(states == states_getter))142 143 states_getter = sim.qubits.prob[:10]144 states = sim.qubits.get_states(qgate.simulator.prob, key=slice(None, 10))145 self.assertTrue(np.all(states == states_getter))146 147 148import sys149this = sys.modules[__name__]150def setUp(self) :151 self.n_qregs = 20152createTestCases(this, 'TestGetStates', TestGetStatesBase)153class TestGetStates_20bits_CPU(TestGetStatesCPU) :154 def setUp(self) :155 self.n_qregs = 20156if hasattr(qgate.simulator, 'cudaruntime') :157 class TestGetStates_20bits_CUDA(TestGetStatesCUDA) :158 def setUp(self) :...
ffwd_rec.py
Source:ffwd_rec.py
...76FSPKrec = SpikeMonitor(Ffwd, name='FSPKrec')77NErcr.V = np.random.uniform(V_re, V_th, size=Ne)*mV78NIrcr.V = np.random.uniform(V_re, V_th, size=Ni)*mV79run(T, report='text')80# netw_state = magic_network.get_states() # too large81# improvement: can pass argument to get_states82state = {'NErcr' : {k:NErcr.get_states()[k] for k in ['x','y']},83 'NIrcr' : {k:NIrcr.get_states()[k] for k in ['x','y']},84 'S_ee' : {'j' : S_ee.get_states()['j']},85 'S_ie' : {'j' : S_ie.get_states()['j']},86 'S_ei' : {'j' : S_ei.get_states()['j']},87 'S_ii' : {'j' : S_ii.get_states()['j']},88 'S_eF' : {'j' : S_eF.get_states()['j']},89 'S_iF' : {'j' : S_iF.get_states()['j']},90 'Erec' : Erec.get_states(),91 'Irec' : Irec.get_states(),92 'ESPK' : ESPKrec.get_states(),93 'ISPK' : ISPKrec.get_states(),94 'FSPK' : FSPKrec.get_states()95}96import pickle, os97pyname = os.path.splitext(os.path.basename(__file__))[0]98fname = "{:s}_arec{:.2f}_N{:d}_T{:d}ms".format(param_set, a_rec, N, int(T/ms)) 99with open("data/"+fname+".p", "wb") as pfile:...
generate.py
Source:generate.py
1# coding: utf-82from transitions.extensions import GraphMachine3class Model(object):4 pass5states = [6 'Waiting first inputs',7 'Parsing head number',8 'Waiting first inputs without parsing number',9 'Waiting inputs',10 'Accepted'11]12get_states = {13 'first_wait_wnum': states[0],14 'parse_num': states[1],15 'first_wait': states[2],16 'wait': states[3],17 'acc': states[4],18}19transitions = [20 # Initial21 {22 'trigger': 'Empty',23 'source': get_states['first_wait_wnum'],24 'dest': get_states['first_wait_wnum']25 },26 {27 'trigger': 'Numbers except for zero',28 'source': get_states['first_wait_wnum'],29 'dest': get_states['parse_num']30 },31 {32 'trigger': 'Except for numbers',33 'source': get_states['first_wait_wnum'],34 'dest': get_states['wait']35 },36 {37 'trigger': 'call accept()',38 'source': get_states['first_wait_wnum'],39 'dest': get_states['acc']40 },41 # Initial Waiting42 {43 'trigger': 'Empty',44 'source': get_states['first_wait'],45 'dest': get_states['first_wait_wnum']46 },47 {48 'trigger': 'Numbers only except for zero',49 'source': get_states['first_wait'],50 'dest': get_states['first_wait']51 },52 {53 'trigger': 'Except for numbers',54 'source': get_states['first_wait'],55 'dest': get_states['wait']56 },57 {58 'trigger': 'call accept()',59 'source': get_states['first_wait'],60 'dest': get_states['acc']61 },62 # Waiting63 {64 'trigger': 'Input',65 'source': get_states['wait'],66 'dest': get_states['wait']67 },68 {69 'trigger': 'call accept()',70 'source': get_states['wait'],71 'dest': get_states['acc']72 },73 # Accepted74 {75 'trigger': 'Empty',76 'source': get_states['acc'],77 'dest': get_states['first_wait_wnum']78 },79 {80 'trigger': 'Same as previous',81 'source': get_states['acc'],82 'dest': get_states['acc']83 },84 {85 'trigger': 'Input differently (ε-transitions)',86 'source': get_states['acc'],87 'dest': get_states['first_wait']88 },89 {90 'trigger': 'call accept()',91 'source': get_states['acc'],92 'dest': get_states['acc']93 },94 # Parse number95 {96 'trigger': 'Empty',97 'source': get_states['parse_num'],98 'dest': get_states['parse_num']99 },100 {101 'trigger': 'Numbers',102 'source': get_states['parse_num'],103 'dest': get_states['parse_num']104 },105 {106 'trigger': 'Except for numbers',107 'source': get_states['parse_num'],108 'dest': get_states['wait']109 },110 {111 'trigger': 'call accept()',112 'source': get_states['parse_num'],113 'dest': get_states['acc']114 },115]116model = Model()117machine = GraphMachine(118 model=model,119 states=states,120 transitions=transitions,121 initial=get_states['first_wait_wnum'],122 title='NTypeLogger State Transition Diagram')123graph = model.get_graph()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!