Commit d04629cd authored by K-H-Ismail's avatar K-H-Ismail Committed by Gauthier Quesnel
Browse files

test: add van der pol and negatif lif tests

parent 80f4f73e
......@@ -2283,4 +2283,316 @@ main()
expect(st == irt::status::success);
} while (t < 140);
};
"van_der_pol_simulation"_test = [] {
fmt::print("van_der_pol_simulation\n");
irt::simulation sim;
expect(irt::is_success(sim.init(32lu, 512lu)));
expect(sim.adder_3_models.can_alloc(1));
expect(sim.mult_3_models.can_alloc(1));
expect(sim.integrator_models.can_alloc(2));
expect(sim.quantifier_models.can_alloc(2));
auto& sum = sim.adder_3_models.alloc();
auto& product = sim.mult_3_models.alloc();
auto& integrator_a = sim.integrator_models.alloc();
auto& integrator_b = sim.integrator_models.alloc();
auto& quantifier_a = sim.quantifier_models.alloc();
auto& quantifier_b = sim.quantifier_models.alloc();
integrator_a.default_current_value = 0.0;
quantifier_a.default_adapt_state =
irt::quantifier::adapt_state::possible;
quantifier_a.default_zero_init_offset = true;
quantifier_a.default_step_size = 0.01;
quantifier_a.default_past_length = 3;
integrator_b.default_current_value = 10.0;
quantifier_b.default_adapt_state =
irt::quantifier::adapt_state::possible;
quantifier_b.default_zero_init_offset = true;
quantifier_b.default_step_size = 0.01;
quantifier_b.default_past_length = 3;
product.default_input_coeffs[0] = 1.0;
product.default_input_coeffs[1] = 1.0;
product.default_input_coeffs[2] = 1.0;
double mu = 4.0;
sum.default_input_coeffs[0] = mu;
sum.default_input_coeffs[1] = -mu;
sum.default_input_coeffs[2] = -1.0;
expect(sim.models.can_alloc(10));
!expect(irt::is_success(
sim.alloc(sum, sim.adder_3_models.get_id(sum), "sum")));
!expect(irt::is_success(
sim.alloc(product, sim.mult_3_models.get_id(product), "prod")));
!expect(irt::is_success(sim.alloc(
integrator_a, sim.integrator_models.get_id(integrator_a), "int_a")));
!expect(irt::is_success(sim.alloc(
integrator_b, sim.integrator_models.get_id(integrator_b), "int_b")));
!expect(irt::is_success(sim.alloc(
quantifier_a, sim.quantifier_models.get_id(quantifier_a), "qua_a")));
!expect(irt::is_success(sim.alloc(
quantifier_b, sim.quantifier_models.get_id(quantifier_b), "qua_b")));
!expect(sim.models.size() == 6_ul);
expect(sim.connect(integrator_b.y[0], integrator_a.x[1]) ==
irt::status::success);
expect(sim.connect(sum.y[0], integrator_b.x[1]) ==
irt::status::success);
expect(sim.connect(integrator_b.y[0], sum.x[0]) ==
irt::status::success);
expect(sim.connect(product.y[0], sum.x[1]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], sum.x[2]) ==
irt::status::success);
expect(sim.connect(integrator_b.y[0], product.x[0]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], product.x[1]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], product.x[2]) ==
irt::status::success);
expect(sim.connect(quantifier_a.y[0], integrator_a.x[0]) ==
irt::status::success);
expect(sim.connect(quantifier_b.y[0], integrator_b.x[0]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], quantifier_a.x[0]) ==
irt::status::success);
expect(sim.connect(integrator_b.y[0], quantifier_b.x[0]) ==
irt::status::success);
file_output fo_a("van_der_pol_a.csv");
file_output fo_b("van_der_pol_b.csv");
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01,
"A",
static_cast<void*>(&fo_a),
file_output_initialize,
&file_output_observe,
nullptr);
auto& obs_b = sim.observers.alloc(0.01,
"B",
static_cast<void*>(&fo_b),
file_output_initialize,
&file_output_observe,
nullptr);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
irt::time t = 0.0;
expect(sim.initialize(t) == irt::status::success);
!expect(sim.sched.size() == 6_ul);
do {
auto st = sim.run(t);
expect(st == irt::status::success);
} while (t < 150.0);
};
"van_der_pol_simulation_qss3"_test = [] {
fmt::print("van_der_pol_simulation_qss3\n");
irt::simulation sim;
expect(irt::is_success(sim.init(32lu, 512lu)));
expect(sim.qss3_wsum_3_models.can_alloc(1));
expect(sim.qss3_multiplier_models.can_alloc(2));
expect(sim.qss3_integrator_models.can_alloc(2));
auto& sum = sim.qss3_wsum_3_models.alloc();
auto& product1 = sim.qss3_multiplier_models.alloc();
auto& product2 = sim.qss3_multiplier_models.alloc();
auto& integrator_a = sim.qss3_integrator_models.alloc();
auto& integrator_b = sim.qss3_integrator_models.alloc();
integrator_a.default_X = 0.0;
integrator_a.default_dQ = 0.001;
integrator_b.default_X = 10.0;
integrator_b.default_dQ = 0.001;
double mu = 4.0;
sum.default_input_coeffs[0] = mu;
sum.default_input_coeffs[1] = -mu;
sum.default_input_coeffs[2] = -1.0;
expect(sim.models.can_alloc(10));
!expect(irt::is_success(
sim.alloc(sum, sim.qss3_wsum_3_models.get_id(sum), "sum")));
!expect(irt::is_success(
sim.alloc(product1, sim.qss3_multiplier_models.get_id(product1), "prod1")));
!expect(irt::is_success(
sim.alloc(product2, sim.qss3_multiplier_models.get_id(product2), "prod2")));
!expect(irt::is_success(sim.alloc(
integrator_a, sim.qss3_integrator_models.get_id(integrator_a), "int_a")));
!expect(irt::is_success(sim.alloc(
integrator_b, sim.qss3_integrator_models.get_id(integrator_b), "int_b")));
!expect(sim.models.size() == 5_ul);
expect(sim.connect(integrator_b.y[0], integrator_a.x[0]) ==
irt::status::success);
expect(sim.connect(sum.y[0], integrator_b.x[0]) ==
irt::status::success);
expect(sim.connect(integrator_b.y[0], sum.x[0]) ==
irt::status::success);
expect(sim.connect(product2.y[0], sum.x[1]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], sum.x[2]) ==
irt::status::success);
expect(sim.connect(integrator_b.y[0], product1.x[0]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], product1.x[1]) ==
irt::status::success);
expect(sim.connect(product1.y[0], product2.x[0]) ==
irt::status::success);
expect(sim.connect(integrator_a.y[0], product2.x[1]) ==
irt::status::success);
file_output fo_a("van_der_pol_qss3_a.csv");
file_output fo_b("van_der_pol_qss3_b.csv");
expect(fo_a.os != nullptr);
expect(fo_b.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01,
"A",
static_cast<void*>(&fo_a),
file_output_initialize,
&file_output_observe,
nullptr);
auto& obs_b = sim.observers.alloc(0.01,
"B",
static_cast<void*>(&fo_b),
file_output_initialize,
&file_output_observe,
nullptr);
sim.observe(sim.models.get(integrator_a.id), obs_a);
sim.observe(sim.models.get(integrator_b.id), obs_b);
irt::time t = 0.0;
expect(sim.initialize(t) == irt::status::success);
!expect(sim.sched.size() == 5_ul);
do {
auto st = sim.run(t);
expect(st == irt::status::success);
} while (t < 1500.0);
};
/*
"neg_lif_simulation_qss1"_test = [] {
fmt::print("neg_lif_simulation_qss1\n");
irt::simulation sim;
expect(irt::is_success(sim.init(32lu, 512lu)));
expect(sim.qss1_wsum_2_models.can_alloc(1));
expect(sim.qss1_integrator_models.can_alloc(1));
expect(sim.constant_models.can_alloc(2));
expect(sim.qss1_cross_models.can_alloc(1));
auto& sum = sim.qss1_wsum_2_models.alloc();
auto& integrator = sim.qss1_integrator_models.alloc();
auto& constant = sim.constant_models.alloc();
auto& constant_cross = sim.constant_models.alloc();
auto& cross = sim.qss1_cross_models.alloc();
double tau = 10.0;
double Vt = -1.0;
double V0 = -10.0;
double Vr = 0.0;
sum.default_input_coeffs[0] = -1.0 / tau;
sum.default_input_coeffs[1] = V0 / tau;
constant.default_value = 1.0;
constant_cross.default_value = Vr;
integrator.default_X = 0.0;
integrator.default_dQ = 0.001;
cross.default_threshold = Vt;
expect(sim.models.can_alloc(10));
!expect(irt::is_success(
sim.alloc(sum, sim.qss1_wsum_2_models.get_id(sum), "sum")));
!expect(irt::is_success(sim.alloc(
integrator, sim.qss1_integrator_models.get_id(integrator), "int")));
!expect(irt::is_success(
sim.alloc(constant, sim.constant_models.get_id(constant), "cte")));
!expect(
irt::is_success(sim.alloc(constant_cross,
sim.constant_models.get_id(constant_cross),
"ctecro")));
!expect(irt::is_success(
sim.alloc(cross, sim.qss1_cross_models.get_id(cross), "cro")));
!expect(sim.models.size() == 5_ul);
// Connections
// expect(sim.connect(cross.y[1], integrator.x[0]) ==
// irt::status::success);
expect(sim.connect(cross.y[0], integrator.x[1]) ==
irt::status::success);
expect(sim.connect(cross.y[1], sum.x[0]) == irt::status::success);
expect(sim.connect(integrator.y[0], cross.x[0]) ==
irt::status::success);
expect(sim.connect(integrator.y[0], cross.x[2]) ==
irt::status::success);
expect(sim.connect(constant_cross.y[0], cross.x[1]) ==
irt::status::success);
expect(sim.connect(constant.y[0], sum.x[1]) == irt::status::success);
expect(sim.connect(sum.y[0], integrator.x[0]) == irt::status::success);
file_output fo_a("neg-lif-qss1.csv");
expect(fo_a.os != nullptr);
auto& obs_a = sim.observers.alloc(0.01,
"A",
static_cast<void*>(&fo_a),
file_output_initialize,
&file_output_observe,
nullptr);
sim.observe(sim.models.get(integrator.id), obs_a);
irt::time t = 0.0;
expect(sim.initialize(t) == irt::status::success);
!expect(sim.sched.size() == 5_ul);
do {
auto st = sim.run(t);
expect(st == irt::status::success);
} while (t < 100.0);
};
*/
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment