def templateDynamicSimulationConnectionTypeTest(self, num_osc, weight, connection_type): network = sync_network(num_osc, weight, type_conn = connection_type); output_dynamic = network.simulate_dynamic(collect_dynamic = False); # Just current state of network is required clusters = output_dynamic.allocate_sync_ensembles(0.1); assert len(clusters) == 1;
def templateVisualizerNoFailures(self, size, velocity, ccore_flag): net = sync_network(size, ccore = ccore_flag); output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True); sync_visualizer.animate_correlation_matrix(output_dynamic, velocity); sync_visualizer.animate_output_dynamic(output_dynamic, velocity); sync_visualizer.show_correlation_matrix(output_dynamic); sync_visualizer.show_output_dynamic(output_dynamic);
def testVisualizeLocalOrderParameterNoFailures(self): net = sync_network(10, ccore = False); output_dynamic = net.simulate_static(20, 10, solution = solve_type.FAST, collect_dynamic = True); sync_visualizer.show_local_order_parameter(output_dynamic, net); sync_visualizer.show_local_order_parameter(output_dynamic, net, 0); sync_visualizer.show_local_order_parameter(output_dynamic, net, 5); sync_visualizer.show_local_order_parameter(output_dynamic, net, 5, 20);
def templateConnectionsApi(size, ccore_flag): network = sync_network(size, 1, type_conn = conn_type.ALL_TO_ALL, ccore = ccore_flag); for i in range(len(network)): for j in range(len(network)): if (i != j): assert network.has_connection(i, j) == True; assert len(network.get_neighbors(i)) == size - 1, str(network.get_neighbors(i)); assert len(network.get_neighbors(j)) == size - 1;
def testOutputNormalization(self): network = sync_network(20, 1); (t, dyn) = network.simulate(50, 20, solve_type.RK4); for iteration in range(len(dyn)): for index_oscillator in range(len(dyn[iteration])): assert (dyn[iteration][index_oscillator] >= 0); assert (dyn[iteration][index_oscillator] <= 2.0 * pi);
def testSyncOrderNetwork(self): # Check for order parameter of network with several oscillators network = sync_network(2, 1, ccore=False); sync_state = 1; tolerance = 0.1; network.simulate(50, 20, solve_type.RK4); assert (abs(network.sync_order() - sync_state) < tolerance) == True;
def templateOutputDynamicCalculateLocalOrderParameter(ccore_flag): net = sync_network(5, ccore = ccore_flag); output_dynamic = net.simulate_static(20, 10, solution = solve_type.FAST, collect_dynamic = True); assert len(output_dynamic.calculate_local_order_parameter(net, 0, 20)) == 20; assert len(output_dynamic.calculate_local_order_parameter(net)) == 1; assert len(output_dynamic.calculate_local_order_parameter(net, 5)) == 1; assert len(output_dynamic.calculate_local_order_parameter(net, 5, 10)) == 5; assert output_dynamic.calculate_local_order_parameter(net, 20)[0] > 0.9;
def template_animate_phase_matrix(num_osc, strength = 1.0, steps = None, time = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, ccore_flag = True): network = sync_network(num_osc, strength, type_conn = conn, ccore = ccore_flag); if ( (steps is not None) and (time is not None) ): sync_output_dynamic = network.simulate(steps, time, solution = type_solution, collect_dynamic = True); else: sync_output_dynamic = network.simulate_dynamic(collect_dynamic = True, order = 0.999, solution = type_solution); sync_visualizer.animate_phase_matrix(sync_output_dynamic); return network;
def template_dynamic_sync(num_osc, k = 1, q = 1, sim_arg = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, collect_dyn = True, ccore_flag = False): network = sync_network(num_osc, k, type_conn = conn, ccore = ccore_flag); network.cluster = q; if (sim_arg is not None): (t, dyn_phase) = network.simulate(sim_arg[0], sim_arg[1], solution = type_solution, collect_dynamic = collect_dyn); else: (t, dyn_phase) = network.simulate_dynamic(collect_dynamic = collect_dyn, solution = type_solution); draw_dynamics(t, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]); return network;
def template_dynamic_sync(num_osc, k = 1, sim_arg = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, collect_dyn = True, ccore_flag = False): network = sync_network(num_osc, k, type_conn = conn, ccore = ccore_flag); if (sim_arg is not None): sync_output_dynamic = network.simulate(sim_arg[0], sim_arg[1], solution = type_solution, collect_dynamic = collect_dyn); else: sync_output_dynamic = network.simulate_dynamic(collect_dynamic = collect_dyn, solution = type_solution); sync_visualizer.show_output_dynamic(sync_output_dynamic); sync_visualizer.animate_output_dynamic(sync_output_dynamic); sync_visualizer.animate_correlation_matrix(sync_output_dynamic); return network;
def testOutputNormalization(self): network = sync_network(20, 1, ccore=False); output_dynamic = network.simulate(50, 20, solve_type.RK4); t = output_dynamic.time; dyn = output_dynamic.output; for iteration in range(len(dyn)): for index_oscillator in range(len(dyn[iteration])): assert (dyn[iteration][index_oscillator] >= 0); assert (dyn[iteration][index_oscillator] <= 2.0 * pi);
def templateSimulateTest(self, nodes = 10, weight = 1, solution = solve_type.FAST, ccore_flag = False): sim_time = 20; sim_steps = 50; tolerance = 0.01; network = sync_network(nodes, weight, ccore = ccore_flag); (t, dyn_phase) = network.simulate(sim_steps, sim_time, solution); index = len(dyn_phase) - 1; value = dyn_phase[index][0]; for item in dyn_phase[index]: assert (abs(item - value) < tolerance) == True;
def templateDynamicSimulationConnectionTypeTest(self, num_osc, weight, connection_type): testing_result = False; for _ in range(3): network = sync_network(num_osc, weight, type_conn = connection_type); output_dynamic = network.simulate_dynamic(collect_dynamic = False); # Just current state of network is required clusters = output_dynamic.allocate_sync_ensembles(0.1); if (len(clusters) != 1): continue; testing_result = True; break; assert testing_result == True;
def templateSimulateTest(nodes, weight, solution, ccore_flag): sim_time = 20; sim_steps = 50; tolerance = 0.01; network = sync_network(nodes, weight, ccore = ccore_flag); output_dynamic = network.simulate(sim_steps, sim_time, solution); dyn_phase = output_dynamic.output; index = len(dyn_phase) - 1; value = dyn_phase[index][0]; for item in dyn_phase[index]: if ((abs(item - value) < tolerance) != True): print(dyn_phase[:][0]); assert (abs(item - value) < tolerance) == True;
def testSyncOrderSingleOscillator(self): # Check for order parameter of network with one oscillator network = sync_network(1, 1, ccore=False); assert network.sync_order() == 1;
def testOutputDynamicLengthStaticSimulationWithouCollecting(self): net = sync_network(5, ccore=False); output_dynamic = net.simulate_static(10, 10, solution = solve_type.FAST, collect_dynamic = False); assert len(output_dynamic) == 1; # 10 steps without initial values.
def testOutputDynamicLengthDynamicSimulationWithoutCollecting(self): net = sync_network(5, ccore=False); output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = False); assert len(output_dynamic) == 1;
def testSyncLocalOrderSingleOscillator(self): network = sync_network(1, 1) assert network.sync_local_order() == 0
def testOutputDinamicLengthSimulation(self): net = sync_network(5); output_dynamic = net.simulate(10, 10, solution = solve_type.FAST, collect_dynamic = True); assert len(output_dynamic) == 11; # 10 steps without initial values.
def testCreate(self): network = sync_network(10, 1); assert network.num_osc == 10;
def testCreate(self): network = sync_network(10, 1) assert len(network) == 10
def testOutputDynamicLengthDynamicSimulation(self): net = sync_network(5); output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True); assert len(output_dynamic) > 1;
def template_animate_output_dynamic(title, amount_oscillators, coupling_stregth, frequency, order): network = sync_network(amount_oscillators, coupling_stregth, frequency, ccore = True); sync_output_dynamic = network.simulate_dynamic(order, solution = solve_type.RK4, collect_dynamic = True); sync_visualizer.animate(sync_output_dynamic, title);
def templateCreateNetwork(size, ccore_flag): network = sync_network(size, 1, ccore=ccore_flag) assert len(network) == size
def testCreate(self): network = sync_network(10, 1); assert len(network) == 10;
def templateCreateNetwork(size, ccore_flag): network = sync_network(size, 1, ccore = ccore_flag); assert len(network) == size;
def testCreationDeletionByCore(self): # Crash occurs in case of memory leak for iteration in range(0, 15): network = sync_network(4096, 1, type_conn = conn_type.ALL_TO_ALL, ccore = True); del network;
def testSyncLocalOrderSingleOscillator(self): network = sync_network(1, 1); assert network.sync_local_order() == 0;
def testOutputDynamicLengthSimulation(self): net = sync_network(5); output_dynamic = net.simulate(10, 10, solution = solve_type.FAST, collect_dynamic = True); assert len(output_dynamic) == 11; # 10 steps without initial values.
def testSyncOrderSingleOscillator(self): # Check for order parameter of network with one oscillator network = sync_network(1, 1, ccore=False) assert network.sync_order() == 1
def testCreate(self): network = sync_network(10, 1) assert network.num_osc == 10
def templateDynamicSimulationConvergence(self, num_osc, weight, connection_type, ccore_flag): network = sync_network(num_osc, weight, type_conn = connection_type, initial_phases=initial_type.EQUIPARTITION, ccore = ccore_flag); output_dynamic = network.simulate_dynamic(collect_dynamic = False); # Just current state of network is required clusters = output_dynamic.allocate_sync_ensembles(0.1); assert len(clusters) == 1;
def template_animate_output_dynamic(title, amount_oscillators, coupling_stregth, frequency, order): network = sync_network(amount_oscillators, coupling_stregth, frequency, ccore = True); sync_output_dynamic = network.simulate_dynamic(order, solution = solve_type.RK4, collect_dynamic = True); sync_visualizer.animate(sync_output_dynamic, title, title + ".mp4");
def testOutputDynamicLengthStaticSimulationWithouCollecting(self): net = sync_network(5); output_dynamic = net.simulate_static(10, 10, solution = solve_type.FAST, collect_dynamic = False); assert len(output_dynamic) == 1; # 10 steps without initial values.
def testCreationDeletionByCore(self): # Crash occurs in case of memory leak for _ in range(0, 15): network = sync_network(4096, 1, type_conn = conn_type.ALL_TO_ALL, ccore = True); del network;
def testOutputDynamicLengthDynamicSimulationWithoutCollecting(self): net = sync_network(5); output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = False); assert len(output_dynamic) == 1;
def templateDynamicSimulationConvergence(self, num_osc, weight, connection_type, ccore_flag): network = sync_network(num_osc, weight, type_conn = connection_type, initial_phases=initial_type.EQUIPARTITION, ccore = ccore_flag); (t, dyn) = network.simulate_dynamic(collect_dynamic = False); # Just current state of network is required clusters = network.allocate_sync_ensembles(0.1); assert len(clusters) == 1;