myokit 1.33.9__py3-none-any.whl → 1.35.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- myokit/__init__.py +9 -36
- myokit/__main__.py +76 -142
- myokit/_aux.py +62 -16
- myokit/_bin/example.mmt +1 -2
- myokit/_bin/install-win/menu.json +7 -7
- myokit/_config.py +22 -31
- myokit/_datablock.py +30 -74
- myokit/_datalog.py +49 -72
- myokit/_err.py +25 -24
- myokit/_expressions.py +50 -68
- myokit/_io.py +15 -27
- myokit/_model_api.py +453 -249
- myokit/_myokit_version.py +1 -5
- myokit/_parsing.py +38 -44
- myokit/_progress.py +5 -8
- myokit/_protocol.py +99 -9
- myokit/_sim/__init__.py +7 -24
- myokit/_sim/cable.c +6 -8
- myokit/_sim/cable.py +6 -8
- myokit/_sim/cmodel.h +125 -70
- myokit/_sim/cmodel.py +12 -14
- myokit/_sim/compiler.py +1 -4
- myokit/_sim/cvodessim.c +196 -118
- myokit/_sim/cvodessim.py +130 -103
- myokit/_sim/differential.hpp +4 -4
- myokit/_sim/fiber_tissue.c +4 -8
- myokit/_sim/fiber_tissue.py +11 -13
- myokit/_sim/jacobian.cpp +2 -2
- myokit/_sim/jacobian.py +11 -8
- myokit/_sim/mcl.h +53 -55
- myokit/_sim/opencl.py +21 -27
- myokit/_sim/openclsim.c +3 -7
- myokit/_sim/openclsim.cl +3 -3
- myokit/_sim/openclsim.py +49 -40
- myokit/_sim/pacing.h +36 -16
- myokit/_sim/rhs.c +6 -13
- myokit/_sim/rhs.py +5 -14
- myokit/_sim/sundials.py +1 -4
- myokit/_system.py +10 -16
- myokit/_unit.py +4 -13
- myokit/float.py +0 -3
- myokit/formats/__init__.py +8 -10
- myokit/formats/ansic/__init__.py +0 -3
- myokit/formats/ansic/_ewriter.py +2 -4
- myokit/formats/ansic/_exporter.py +1 -4
- myokit/formats/ansic/template/cable.c +4 -4
- myokit/formats/ansic/template/euler.c +5 -5
- myokit/formats/ansic/template/sim.c +6 -6
- myokit/formats/axon/__init__.py +1 -3
- myokit/formats/axon/_abf.py +12 -17
- myokit/formats/axon/_atf.py +5 -6
- myokit/formats/axon/_importer.py +0 -3
- myokit/formats/cellml/__init__.py +0 -3
- myokit/formats/cellml/_ewriter.py +3 -6
- myokit/formats/cellml/_exporter.py +3 -6
- myokit/formats/cellml/_importer.py +1 -4
- myokit/formats/cellml/v1/__init__.py +0 -4
- myokit/formats/cellml/v1/_api.py +8 -11
- myokit/formats/cellml/v1/_parser.py +2 -5
- myokit/formats/cellml/v1/_writer.py +2 -11
- myokit/formats/cellml/v2/__init__.py +0 -3
- myokit/formats/cellml/v2/_api.py +8 -17
- myokit/formats/cellml/v2/_parser.py +2 -5
- myokit/formats/cellml/v2/_writer.py +1 -4
- myokit/formats/channelml/__init__.py +0 -3
- myokit/formats/channelml/_importer.py +11 -21
- myokit/formats/cpp/__init__.py +1 -3
- myokit/formats/cpp/_ewriter.py +0 -3
- myokit/formats/cuda/__init__.py +0 -3
- myokit/formats/cuda/_ewriter.py +2 -4
- myokit/formats/cuda/_exporter.py +0 -3
- myokit/formats/cuda/template/kernel.cu +8 -5
- myokit/formats/easyml/__init__.py +0 -3
- myokit/formats/easyml/_ewriter.py +9 -11
- myokit/formats/easyml/_exporter.py +2 -5
- myokit/formats/html/__init__.py +0 -3
- myokit/formats/html/_exporter.py +0 -3
- myokit/formats/html/_flatten.py +5 -21
- myokit/formats/latex/__init__.py +0 -3
- myokit/formats/latex/_ewriter.py +1 -4
- myokit/formats/latex/_exporter.py +4 -6
- myokit/formats/mathml/__init__.py +0 -3
- myokit/formats/mathml/_ewriter.py +2 -11
- myokit/formats/mathml/_parser.py +4 -6
- myokit/formats/matlab/__init__.py +0 -3
- myokit/formats/matlab/_ewriter.py +1 -4
- myokit/formats/matlab/_exporter.py +2 -5
- myokit/formats/matlab/template/main.m +3 -2
- myokit/formats/opencl/__init__.py +0 -3
- myokit/formats/opencl/_ewriter.py +2 -4
- myokit/formats/opencl/_exporter.py +2 -5
- myokit/formats/opencl/template/cable.c +10 -10
- myokit/formats/opencl/template/kernel.cl +1 -1
- myokit/formats/opencl/template/minilog.py +1 -1
- myokit/formats/python/__init__.py +0 -3
- myokit/formats/python/_ewriter.py +2 -5
- myokit/formats/python/_exporter.py +0 -3
- myokit/formats/python/template/sim.py +14 -14
- myokit/formats/sbml/__init__.py +0 -3
- myokit/formats/sbml/_api.py +50 -44
- myokit/formats/sbml/_importer.py +1 -4
- myokit/formats/sbml/_parser.py +2 -5
- myokit/formats/stan/__init__.py +0 -3
- myokit/formats/stan/_ewriter.py +2 -4
- myokit/formats/stan/_exporter.py +2 -5
- myokit/formats/stan/template/cell.stan +3 -3
- myokit/formats/sympy/__init__.py +0 -3
- myokit/formats/sympy/_ereader.py +1 -4
- myokit/formats/sympy/_ewriter.py +2 -5
- myokit/formats/wcp/__init__.py +0 -3
- myokit/formats/wcp/_wcp.py +2 -8
- myokit/formats/xml/__init__.py +0 -3
- myokit/formats/xml/_exporter.py +0 -3
- myokit/formats/xml/_split.py +0 -3
- myokit/gui/__init__.py +80 -246
- myokit/gui/datablock_viewer.py +103 -86
- myokit/gui/datalog_viewer.py +214 -66
- myokit/gui/explorer.py +15 -21
- myokit/gui/ide.py +171 -144
- myokit/gui/progress.py +9 -9
- myokit/gui/source.py +406 -375
- myokit/gui/vargrapher.py +2 -12
- myokit/lib/deps.py +12 -13
- myokit/lib/guess.py +3 -4
- myokit/lib/hh.py +20 -18
- myokit/lib/markov.py +21 -20
- myokit/lib/multi.py +1 -3
- myokit/lib/plots.py +20 -9
- myokit/pacing.py +0 -3
- myokit/pype.py +7 -18
- myokit/tests/__init__.py +3 -6
- myokit/tests/ansic_event_based_pacing.py +1 -4
- myokit/tests/ansic_fixed_form_pacing.py +3 -6
- myokit/tests/data/beeler-1977-model-compare-b.mmt +2 -2
- myokit/tests/data/clancy-1999-fitting.mmt +1 -0
- myokit/tests/test_aux.py +13 -28
- myokit/tests/test_cellml_v1_api.py +4 -19
- myokit/tests/test_cellml_v1_parser.py +0 -15
- myokit/tests/test_cellml_v1_writer.py +0 -9
- myokit/tests/test_cellml_v2_api.py +4 -19
- myokit/tests/test_cellml_v2_parser.py +0 -15
- myokit/tests/test_cellml_v2_writer.py +0 -9
- myokit/tests/test_cmodel.py +16 -22
- myokit/tests/test_compiler_detection.py +1 -11
- myokit/tests/test_component.py +108 -56
- myokit/tests/test_config.py +34 -67
- myokit/tests/test_datablock.py +1 -9
- myokit/tests/test_datalog.py +19 -24
- myokit/tests/test_dependency_checking.py +8 -23
- myokit/tests/test_expressions.py +0 -9
- myokit/tests/test_float.py +1 -5
- myokit/tests/test_formats.py +0 -9
- myokit/tests/test_formats_axon.py +1 -9
- myokit/tests/test_formats_cellml.py +0 -15
- myokit/tests/test_formats_channelml.py +0 -15
- myokit/tests/test_formats_easyml.py +0 -14
- myokit/tests/test_formats_exporters.py +1 -16
- myokit/tests/test_formats_expression_writers.py +1 -17
- myokit/tests/test_formats_html.py +0 -3
- myokit/tests/test_formats_importers.py +1 -16
- myokit/tests/test_formats_mathml_content.py +0 -9
- myokit/tests/test_formats_mathml_presentation.py +0 -9
- myokit/tests/test_formats_opencl.py +0 -10
- myokit/tests/test_formats_sbml.py +0 -15
- myokit/tests/test_formats_sympy.py +0 -9
- myokit/tests/test_formats_wcp.py +1 -3
- myokit/tests/test_io.py +27 -27
- myokit/tests/test_jacobian_calculator.py +6 -14
- myokit/tests/test_jacobian_tracer.py +0 -9
- myokit/tests/test_lib_deps.py +0 -9
- myokit/tests/test_lib_guess.py +0 -9
- myokit/tests/test_lib_hh.py +18 -12
- myokit/tests/test_lib_markov.py +21 -13
- myokit/tests/test_lib_multi.py +0 -9
- myokit/tests/test_lib_plots.py +13 -8
- myokit/tests/test_meta.py +0 -3
- myokit/tests/test_model.py +390 -96
- myokit/tests/test_model_building.py +44 -96
- myokit/tests/test_opencl_info.py +5 -14
- myokit/tests/test_pacing_factory.py +0 -3
- myokit/tests/test_pacing_system_c.py +1 -23
- myokit/tests/test_pacing_system_py.py +0 -9
- myokit/tests/test_parsing.py +139 -56
- myokit/tests/test_progress_reporters.py +0 -3
- myokit/tests/test_protocol.py +0 -9
- myokit/tests/test_protocol_floating_point.py +1 -10
- myokit/tests/test_protocol_time_series.py +82 -0
- myokit/tests/test_pype.py +0 -9
- myokit/tests/test_quantity.py +0 -9
- myokit/tests/test_rhs_benchmarker.py +1 -9
- myokit/tests/test_sbml_api.py +27 -42
- myokit/tests/test_sbml_parser.py +4 -19
- myokit/tests/test_simulation_1d.py +45 -25
- myokit/tests/test_simulation_cvodes.py +321 -55
- myokit/tests/test_simulation_cvodes_from_disk.py +0 -3
- myokit/tests/test_simulation_fiber_tissue.py +39 -12
- myokit/tests/test_simulation_log_interval.py +1 -431
- myokit/tests/test_simulation_opencl.py +69 -48
- myokit/tests/test_simulation_opencl_log_interval.py +1 -3
- myokit/tests/test_simulation_opencl_vs_cvode.py +1 -10
- myokit/tests/test_simulation_opencl_vs_sim1d.py +1 -10
- myokit/tests/test_system_info.py +1 -11
- myokit/tests/test_tools.py +0 -9
- myokit/tests/test_unit.py +1 -10
- myokit/tests/test_user_functions.py +0 -10
- myokit/tests/test_variable.py +231 -27
- myokit/tools.py +5 -21
- myokit/units.py +5 -3
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/METADATA +12 -15
- myokit-1.35.0.dist-info/RECORD +391 -0
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/WHEEL +1 -1
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/entry_points.txt +0 -1
- myokit/_exec_new.py +0 -15
- myokit/_exec_old.py +0 -15
- myokit/_sim/cvodesim.c +0 -1551
- myokit/_sim/cvodesim.py +0 -674
- myokit/_sim/icsim.cpp +0 -563
- myokit/_sim/icsim.py +0 -363
- myokit/_sim/psim.cpp +0 -656
- myokit/_sim/psim.py +0 -493
- myokit/lib/common.py +0 -1094
- myokit/tests/test_lib_common.py +0 -130
- myokit/tests/test_simulation_cvode.py +0 -612
- myokit/tests/test_simulation_ic.py +0 -108
- myokit/tests/test_simulation_p.py +0 -223
- myokit-1.33.9.dist-info/RECORD +0 -403
- /myokit/formats/opencl/template/{test → test.sh} +0 -0
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/LICENSE.txt +0 -0
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/top_level.txt +0 -0
myokit/_sim/cmodel.h
CHANGED
|
@@ -45,7 +45,8 @@ States:
|
|
|
45
45
|
State derivatives:
|
|
46
46
|
Calculated by the model.
|
|
47
47
|
Bound variables:
|
|
48
|
-
External inputs to the model (e.g. time and pacing).
|
|
48
|
+
External inputs to the model (e.g. time and pacing). There are an arbitrary
|
|
49
|
+
number of these, and the model stores the current value of each
|
|
49
50
|
Intermediary variables:
|
|
50
51
|
The remaining variables that depend on state variables.
|
|
51
52
|
Constants:
|
|
@@ -153,7 +154,7 @@ will be a myokit.DataLog.
|
|
|
153
154
|
|
|
154
155
|
Methods:
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
Model_InitializeLogging(Model model, PyObject* log_dict)
|
|
157
158
|
Sets up logging for all variables used as keys in log_dict (assuming fully
|
|
158
159
|
qualified names). Will raise an error if the dict contains keys that do not
|
|
159
160
|
correspond to model variables. The values in the dict should implement the
|
|
@@ -163,9 +164,9 @@ Model_Log(model)
|
|
|
163
164
|
If logging has been set up, this will log the current values of variables
|
|
164
165
|
to the sequences in the log dict.
|
|
165
166
|
|
|
166
|
-
|
|
167
|
-
De-
|
|
168
|
-
set up differently, i.e. before a new call to
|
|
167
|
+
Model_DeInitializeLogging(model)
|
|
168
|
+
De-initializes logging. This only needs to be called if logging needs to be
|
|
169
|
+
set up differently, i.e. before a new call to Model_InitializeLogging.
|
|
169
170
|
|
|
170
171
|
Logging sensitivities
|
|
171
172
|
=====================
|
|
@@ -207,13 +208,15 @@ typedef int Model_Flag;
|
|
|
207
208
|
/* General */
|
|
208
209
|
#define Model_INVALID_MODEL -100
|
|
209
210
|
/* Logging */
|
|
210
|
-
#define
|
|
211
|
-
#define
|
|
211
|
+
#define Model_LOGGING_ALREADY_INITIALIZED -200
|
|
212
|
+
#define Model_LOGGING_NOT_INITIALIZED -201
|
|
212
213
|
#define Model_UNKNOWN_VARIABLES_IN_LOG -202
|
|
213
214
|
#define Model_LOG_APPEND_FAILED -203
|
|
214
215
|
/* Logging sensitivities */
|
|
215
216
|
#define Model_NO_SENSITIVITIES_TO_LOG -300
|
|
216
217
|
#define Model_SENSITIVITY_LOG_APPEND_FAILED -303
|
|
218
|
+
/* Pacing */
|
|
219
|
+
#define Model_INVALID_PACING -400
|
|
217
220
|
|
|
218
221
|
/* Caching doesn't help much when running without jacobians etc., so disabled
|
|
219
222
|
for now
|
|
@@ -240,11 +243,11 @@ Model_SetPyErr(Model_Flag flag)
|
|
|
240
243
|
PyErr_SetString(PyExc_Exception, "CModel error: Invalid model pointer provided.");
|
|
241
244
|
break;
|
|
242
245
|
/* Logging */
|
|
243
|
-
case
|
|
244
|
-
PyErr_SetString(PyExc_Exception, "CModel error: Logging
|
|
246
|
+
case Model_LOGGING_ALREADY_INITIALIZED:
|
|
247
|
+
PyErr_SetString(PyExc_Exception, "CModel error: Logging initialized twice.");
|
|
245
248
|
break;
|
|
246
|
-
case
|
|
247
|
-
PyErr_SetString(PyExc_Exception, "CModel error: Logging not
|
|
249
|
+
case Model_LOGGING_NOT_INITIALIZED:
|
|
250
|
+
PyErr_SetString(PyExc_Exception, "CModel error: Logging not initialized.");
|
|
248
251
|
break;
|
|
249
252
|
case Model_UNKNOWN_VARIABLES_IN_LOG:
|
|
250
253
|
PyErr_SetString(PyExc_Exception, "CModel error: Unknown variables found in logging dictionary.");
|
|
@@ -259,7 +262,9 @@ Model_SetPyErr(Model_Flag flag)
|
|
|
259
262
|
case Model_SENSITIVITY_LOG_APPEND_FAILED:
|
|
260
263
|
PyErr_SetString(PyExc_Exception, "CModel error: Call to append() failed on sensitivity matrix logging list.");
|
|
261
264
|
break;
|
|
262
|
-
|
|
265
|
+
case Model_INVALID_PACING:
|
|
266
|
+
PyErr_SetString(PyExc_Exception, "CModel error: Invalid pacing provided.");
|
|
267
|
+
break;
|
|
263
268
|
/* Unknown */
|
|
264
269
|
default:
|
|
265
270
|
PyErr_Format(PyExc_Exception, "CModel error: Unlisted error %d", (int)flag);
|
|
@@ -277,9 +282,12 @@ struct Model_Memory {
|
|
|
277
282
|
/* If this model has sensitivities this will be 1, otherwise 0. */
|
|
278
283
|
int has_sensitivities;
|
|
279
284
|
|
|
285
|
+
/* Pacing */
|
|
286
|
+
realtype *pace_values;
|
|
287
|
+
int n_pace;
|
|
288
|
+
|
|
280
289
|
/* Bound variables */
|
|
281
290
|
realtype time;
|
|
282
|
-
realtype pace;
|
|
283
291
|
realtype realtime;
|
|
284
292
|
realtype evaluations;
|
|
285
293
|
|
|
@@ -326,8 +334,8 @@ struct Model_Memory {
|
|
|
326
334
|
int ns_intermediary;
|
|
327
335
|
realtype* s_intermediary;
|
|
328
336
|
|
|
329
|
-
/* Logging
|
|
330
|
-
int
|
|
337
|
+
/* Logging initialized? */
|
|
338
|
+
int logging_initialized;
|
|
331
339
|
|
|
332
340
|
/* Which variables are we logging? */
|
|
333
341
|
int logging_states;
|
|
@@ -444,6 +452,41 @@ Model_ClearCache(Model model)
|
|
|
444
452
|
return Model_OK;
|
|
445
453
|
}
|
|
446
454
|
|
|
455
|
+
/*
|
|
456
|
+
* Sets up (i.e. allocates memory for) array of protocol-determined values
|
|
457
|
+
*
|
|
458
|
+
* Arguments
|
|
459
|
+
* n_pace: the number of pacing values to use.
|
|
460
|
+
*
|
|
461
|
+
* Returns a model flag.
|
|
462
|
+
*
|
|
463
|
+
*/
|
|
464
|
+
Model_Flag
|
|
465
|
+
Model_SetupPacing(Model model, int n_pace)
|
|
466
|
+
{
|
|
467
|
+
if (model == NULL) return Model_INVALID_MODEL;
|
|
468
|
+
if (n_pace < 0) return Model_INVALID_PACING;
|
|
469
|
+
|
|
470
|
+
/* Free any existing pacing */
|
|
471
|
+
if (model->n_pace > 0) {
|
|
472
|
+
free(model->pace_values);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/* Allocate new pacing */
|
|
476
|
+
model->n_pace = n_pace;
|
|
477
|
+
model->pace_values = (realtype*)malloc((size_t)n_pace * sizeof(realtype));
|
|
478
|
+
if (model->pace_values == NULL) {
|
|
479
|
+
return Model_OUT_OF_MEMORY;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/* Clear values */
|
|
483
|
+
for (int i = 0; i < n_pace; i++) {
|
|
484
|
+
model->pace_values[i] = 0;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return Model_OK;
|
|
488
|
+
}
|
|
489
|
+
|
|
447
490
|
/*
|
|
448
491
|
* (Re)calculates the values of all constants that are derived from other
|
|
449
492
|
* constants.
|
|
@@ -503,14 +546,14 @@ for eq in parameter_derived.values():
|
|
|
503
546
|
* literals : An array of size model->n_literals
|
|
504
547
|
*
|
|
505
548
|
* Returns a model flag.
|
|
506
|
-
|
|
549
|
+
*
|
|
507
550
|
Model_Flag
|
|
508
551
|
Model_SetLiteralVariables(Model model, const realtype* literals)
|
|
509
552
|
{
|
|
510
553
|
int i;
|
|
511
554
|
if (model == NULL) return Model_INVALID_MODEL;
|
|
512
555
|
|
|
513
|
-
|
|
556
|
+
* Scan for changes *
|
|
514
557
|
i = 0;
|
|
515
558
|
#ifdef Model_CACHING
|
|
516
559
|
if (Model__ValidCache(model)) {
|
|
@@ -522,7 +565,7 @@ Model_SetLiteralVariables(Model model, const realtype* literals)
|
|
|
522
565
|
}
|
|
523
566
|
#endif
|
|
524
567
|
|
|
525
|
-
|
|
568
|
+
* Update remaining *
|
|
526
569
|
if (i < model->n_literals) {
|
|
527
570
|
for (; i<model->n_literals; i++) {
|
|
528
571
|
model->literals[i] = literals[i];
|
|
@@ -535,7 +578,7 @@ Model_SetLiteralVariables(Model model, const realtype* literals)
|
|
|
535
578
|
}
|
|
536
579
|
|
|
537
580
|
return Model_OK;
|
|
538
|
-
}
|
|
581
|
+
}*/
|
|
539
582
|
|
|
540
583
|
/*
|
|
541
584
|
* Updates the parameter variables to the values given in `parameters`.
|
|
@@ -657,25 +700,35 @@ Model_SetParametersFromIndependents(Model model, const realtype* independents)
|
|
|
657
700
|
Model_Flag
|
|
658
701
|
Model_SetBoundVariables(
|
|
659
702
|
Model model,
|
|
660
|
-
const realtype time,
|
|
661
|
-
const realtype
|
|
703
|
+
const realtype time,
|
|
704
|
+
const realtype *pace_values,
|
|
705
|
+
const realtype realtime,
|
|
706
|
+
const realtype evaluations)
|
|
662
707
|
{
|
|
708
|
+
#ifdef Model_CACHING
|
|
663
709
|
int changed;
|
|
710
|
+
#endif
|
|
664
711
|
if (model == NULL) return Model_INVALID_MODEL;
|
|
665
712
|
|
|
713
|
+
#ifdef Model_CACHING
|
|
666
714
|
changed = 0;
|
|
715
|
+
#endif
|
|
667
716
|
if (time != model->time) {
|
|
668
717
|
model->time = time;
|
|
718
|
+
#ifdef Model_CACHING
|
|
669
719
|
changed = 1;
|
|
720
|
+
#endif
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
for (int i = 0; i < model->n_pace; i++) {
|
|
724
|
+
if (pace_values[i] != model->pace_values[i]) {
|
|
725
|
+
model->pace_values[i] = pace_values[i];
|
|
726
|
+
#ifdef Model_CACHING
|
|
727
|
+
changed = 1;
|
|
728
|
+
#endif
|
|
729
|
+
}
|
|
670
730
|
}
|
|
671
731
|
|
|
672
|
-
<?
|
|
673
|
-
if model.binding('pace') is not None:
|
|
674
|
-
print(tab + 'if (pace != model->pace) {')
|
|
675
|
-
print(tab + ' model->pace = pace;')
|
|
676
|
-
print(tab + ' changed = 1;')
|
|
677
|
-
print(tab + '}')
|
|
678
|
-
?>
|
|
679
732
|
#ifdef Model_CACHING
|
|
680
733
|
if (changed) {
|
|
681
734
|
Model__InvalidateCache(model);
|
|
@@ -690,7 +743,7 @@ if model.binding('pace') is not None:
|
|
|
690
743
|
}
|
|
691
744
|
|
|
692
745
|
/*
|
|
693
|
-
* Updates the state variables to the values given in `states`.
|
|
746
|
+
* Updates the state variables to the float values given in `states`.
|
|
694
747
|
*
|
|
695
748
|
* If any of the values are changed, the model caches are cleared.
|
|
696
749
|
*
|
|
@@ -865,13 +918,11 @@ for eqs in s_output_equations:
|
|
|
865
918
|
* Private method: Add a variable to the logging lists. Returns 1 if
|
|
866
919
|
* successful.
|
|
867
920
|
*
|
|
868
|
-
* Note: The variable names are all ascii compatible.
|
|
869
|
-
* inside log_dict are either unicode or bytes, but they can be matched
|
|
870
|
-
* without conversion.
|
|
921
|
+
* Note: The variable names are all ascii compatible.
|
|
871
922
|
*
|
|
872
923
|
* Arguments
|
|
873
924
|
* log_dict : A dictionary mapping variable names to sequences.
|
|
874
|
-
* i : The next
|
|
925
|
+
* i : The next index to add logs and vars.
|
|
875
926
|
* name : The name to check.
|
|
876
927
|
* var : A pointer to the variable.
|
|
877
928
|
*
|
|
@@ -893,30 +944,30 @@ Model__AddVariableToLog(
|
|
|
893
944
|
}
|
|
894
945
|
|
|
895
946
|
/*
|
|
896
|
-
*
|
|
897
|
-
* is already
|
|
947
|
+
* Initializes logging, using the given dict. An error is returned if logging
|
|
948
|
+
* is already initialized.
|
|
898
949
|
*
|
|
899
950
|
* Arguments
|
|
900
|
-
* model : The model whose logging system to
|
|
951
|
+
* model : The model whose logging system to initialize.
|
|
901
952
|
* log_dict : A Python dict mapping fully qualified variable names to sequence
|
|
902
953
|
* objects to log in.
|
|
903
954
|
*
|
|
904
955
|
* Returns a model flag
|
|
905
956
|
*/
|
|
906
957
|
Model_Flag
|
|
907
|
-
|
|
958
|
+
Model_InitializeLogging(Model model, PyObject* log_dict)
|
|
908
959
|
{
|
|
909
960
|
int i, j;
|
|
910
961
|
|
|
911
962
|
if (model == NULL) return Model_INVALID_MODEL;
|
|
912
|
-
if (model->
|
|
963
|
+
if (model->logging_initialized) return Model_LOGGING_ALREADY_INITIALIZED;
|
|
913
964
|
|
|
914
965
|
/* Number of variables to log */
|
|
915
|
-
model->n_logged_variables = PyDict_Size(log_dict);
|
|
966
|
+
model->n_logged_variables = (int)PyDict_Size(log_dict);
|
|
916
967
|
|
|
917
968
|
/* Allocate pointer lists */
|
|
918
|
-
model->_log_lists = (PyObject**)malloc(
|
|
919
|
-
model->_log_vars = (realtype**)malloc(
|
|
969
|
+
model->_log_lists = (PyObject**)malloc((size_t)model->n_logged_variables * sizeof(PyObject*));
|
|
970
|
+
model->_log_vars = (realtype**)malloc((size_t)model->n_logged_variables * sizeof(realtype*));
|
|
920
971
|
|
|
921
972
|
/* Check states */
|
|
922
973
|
i = 0;
|
|
@@ -959,24 +1010,24 @@ for var in model.variables(deep=True, state=False, bound=False, const=False):
|
|
|
959
1010
|
}
|
|
960
1011
|
|
|
961
1012
|
/* All done! */
|
|
962
|
-
model->
|
|
1013
|
+
model->logging_initialized = 1;
|
|
963
1014
|
return Model_OK;
|
|
964
1015
|
}
|
|
965
1016
|
|
|
966
1017
|
/*
|
|
967
|
-
* De-
|
|
968
|
-
* allowing logging to be
|
|
1018
|
+
* De-initializes logging, undoing the effects of Model_InitializeLogging() and
|
|
1019
|
+
* allowing logging to be initialized again.
|
|
969
1020
|
*
|
|
970
1021
|
* Arguments
|
|
971
|
-
* model : The model whos logging to
|
|
1022
|
+
* model : The model whos logging to deinitialize.
|
|
972
1023
|
*
|
|
973
1024
|
* Returns a model flag.
|
|
974
1025
|
*/
|
|
975
1026
|
Model_Flag
|
|
976
|
-
|
|
1027
|
+
Model_DeInitializeLogging(Model model)
|
|
977
1028
|
{
|
|
978
1029
|
if (model == NULL) return Model_INVALID_MODEL;
|
|
979
|
-
if (!model->
|
|
1030
|
+
if (!model->logging_initialized) return Model_LOGGING_NOT_INITIALIZED;
|
|
980
1031
|
|
|
981
1032
|
/* Free memory */
|
|
982
1033
|
if (model->_log_vars != NULL) {
|
|
@@ -989,7 +1040,7 @@ Model_DeInitialiseLogging(Model model)
|
|
|
989
1040
|
}
|
|
990
1041
|
|
|
991
1042
|
/* Reset */
|
|
992
|
-
model->
|
|
1043
|
+
model->logging_initialized = 0;
|
|
993
1044
|
model->n_logged_variables = 0;
|
|
994
1045
|
model->logging_states = 0;
|
|
995
1046
|
model->logging_derivatives = 0;
|
|
@@ -1001,7 +1052,7 @@ Model_DeInitialiseLogging(Model model)
|
|
|
1001
1052
|
|
|
1002
1053
|
/*
|
|
1003
1054
|
* Logs the current state of the model to the logging dict passed in to
|
|
1004
|
-
*
|
|
1055
|
+
* Model_InitializeLogging.
|
|
1005
1056
|
*
|
|
1006
1057
|
* Note: This method does not update the state in any way, e.g. to make sure
|
|
1007
1058
|
* that what is logged is sensible.
|
|
@@ -1018,7 +1069,7 @@ Model_Log(Model model)
|
|
|
1018
1069
|
PyObject *val, *ret;
|
|
1019
1070
|
|
|
1020
1071
|
if (model == NULL) return Model_INVALID_MODEL;
|
|
1021
|
-
if (!model->
|
|
1072
|
+
if (!model->logging_initialized) return Model_LOGGING_NOT_INITIALIZED;
|
|
1022
1073
|
|
|
1023
1074
|
for (i=0; i<model->n_logged_variables; i++) {
|
|
1024
1075
|
val = PyFloat_FromDouble(*(model->_log_vars[i]));
|
|
@@ -1037,8 +1088,8 @@ Model_Log(Model model)
|
|
|
1037
1088
|
* Creates a matrix of sensitivities and adds it to a Python sequence.
|
|
1038
1089
|
*
|
|
1039
1090
|
* The created matrix is a (Python) tuple of tuples, where the first (outer)
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1091
|
+
* index is for the dependent variable (y in dy/dx) and the second (inner)
|
|
1092
|
+
* index is for the independent variable (x in dy/dx).
|
|
1042
1093
|
*
|
|
1043
1094
|
* model : The model whose sensitivities to log (must have sensitivity
|
|
1044
1095
|
* calculations enabled).
|
|
@@ -1050,13 +1101,14 @@ Model_Flag
|
|
|
1050
1101
|
Model_LogSensitivityMatrix(Model model, PyObject* list)
|
|
1051
1102
|
{
|
|
1052
1103
|
PyObject *l1, *l2;
|
|
1053
|
-
PyObject *val;
|
|
1054
1104
|
int flag;
|
|
1105
|
+
<?= 'PyObject *val;' if s_dependents else '' ?>
|
|
1055
1106
|
|
|
1056
1107
|
if (model == NULL) return Model_INVALID_MODEL;
|
|
1057
1108
|
|
|
1058
1109
|
/* Create outer tuple */
|
|
1059
1110
|
l1 = PyTuple_New(model->ns_dependents);
|
|
1111
|
+
l2 = NULL; /* Removes "may be unitialized" error */
|
|
1060
1112
|
if (l1 == NULL) goto nomem;
|
|
1061
1113
|
|
|
1062
1114
|
/* Note that PyTuple_SetItem steals a reference */
|
|
@@ -1119,24 +1171,28 @@ Model Model_Create(Model_Flag* flagp)
|
|
|
1119
1171
|
|
|
1120
1172
|
/* States and derivatives */
|
|
1121
1173
|
model->n_states = <?= model.count_states() ?>;
|
|
1122
|
-
model->states = (realtype*)malloc(model->n_states * sizeof(realtype));
|
|
1123
|
-
model->derivatives = (realtype*)malloc(model->n_states * sizeof(realtype));
|
|
1174
|
+
model->states = (realtype*)malloc((size_t)model->n_states * sizeof(realtype));
|
|
1175
|
+
model->derivatives = (realtype*)malloc((size_t)model->n_states * sizeof(realtype));
|
|
1124
1176
|
|
|
1125
1177
|
/* Intermediary variables */
|
|
1126
1178
|
model->n_intermediary = <?= model.count_variables(inter=True, deep=True) ?>;
|
|
1127
|
-
model->intermediary = (realtype*)malloc(model->n_intermediary * sizeof(realtype));
|
|
1179
|
+
model->intermediary = (realtype*)malloc((size_t)model->n_intermediary * sizeof(realtype));
|
|
1128
1180
|
|
|
1129
1181
|
/* Parameters */
|
|
1130
1182
|
model->n_parameters = <?= len(parameters) ?>;
|
|
1131
1183
|
model->n_parameter_derived = <?= len(parameter_derived) ?>;
|
|
1132
|
-
model->parameters = (realtype*)malloc(model->n_parameters * sizeof(realtype));
|
|
1133
|
-
model->parameter_derived = (realtype*)malloc(model->n_parameter_derived * sizeof(realtype));
|
|
1184
|
+
model->parameters = (realtype*)malloc((size_t)model->n_parameters * sizeof(realtype));
|
|
1185
|
+
model->parameter_derived = (realtype*)malloc((size_t)model->n_parameter_derived * sizeof(realtype));
|
|
1186
|
+
|
|
1187
|
+
/* Pacing */
|
|
1188
|
+
model->n_pace = 0;
|
|
1189
|
+
model->pace_values = NULL;
|
|
1134
1190
|
|
|
1135
1191
|
/* Literals */
|
|
1136
1192
|
model->n_literals = <?= len(literals) ?>;
|
|
1137
1193
|
model->n_literal_derived = <?= len(literal_derived) ?>;
|
|
1138
|
-
model->literals = (realtype*)malloc(model->n_literals * sizeof(realtype));
|
|
1139
|
-
model->literal_derived = (realtype*)malloc(model->n_literal_derived * sizeof(realtype));
|
|
1194
|
+
model->literals = (realtype*)malloc((size_t)model->n_literals * sizeof(realtype));
|
|
1195
|
+
model->literal_derived = (realtype*)malloc((size_t)model->n_literal_derived * sizeof(realtype));
|
|
1140
1196
|
|
|
1141
1197
|
/*
|
|
1142
1198
|
* Sensitivities
|
|
@@ -1151,30 +1207,30 @@ Model Model_Create(Model_Flag* flagp)
|
|
|
1151
1207
|
/* Pointers to independent variables */
|
|
1152
1208
|
/* Note that, for sensitivities w.r.t. initial values, the entry in this
|
|
1153
1209
|
list points to the _current_, not the initial value. */
|
|
1154
|
-
model->s_independents = (realtype**)malloc(model->ns_independents * sizeof(realtype));
|
|
1210
|
+
model->s_independents = (realtype**)malloc((size_t)model->ns_independents * sizeof(realtype));
|
|
1155
1211
|
<?
|
|
1156
1212
|
for i, expr in enumerate(s_independents):
|
|
1157
1213
|
print(tab + 'model->s_independents[' + str(i) + '] = &' + v(expr.var()) + ';')
|
|
1158
1214
|
?>
|
|
1159
1215
|
/* Type of independents (1 for parameter, 0 for initial) */
|
|
1160
|
-
model->s_is_parameter = (int*)malloc(model->ns_independents * sizeof(int));
|
|
1216
|
+
model->s_is_parameter = (int*)malloc((size_t)model->ns_independents * sizeof(int));
|
|
1161
1217
|
<?
|
|
1162
1218
|
for i, expr in enumerate(s_independents):
|
|
1163
1219
|
print(tab + 'model->s_is_parameter[' + str(i) + '] = ' + str(1 if isinstance(expr, myokit.Name) else 0) + ';')
|
|
1164
1220
|
?>
|
|
1165
1221
|
/* Sensitivities of state variables */
|
|
1166
|
-
model->s_states = (realtype*)malloc(model->n_states * model->ns_independents * sizeof(realtype));
|
|
1222
|
+
model->s_states = (realtype*)malloc((size_t)(model->n_states * model->ns_independents) * sizeof(realtype));
|
|
1167
1223
|
|
|
1168
1224
|
/* Sensitivities of intermediary variables needed in calculations */
|
|
1169
1225
|
model->ns_intermediary = <?= sum(len(x) for x in s_output_equations) ?>;
|
|
1170
|
-
model->s_intermediary = (realtype*)malloc(model->ns_intermediary * sizeof(realtype));
|
|
1226
|
+
model->s_intermediary = (realtype*)malloc((size_t)model->ns_intermediary * sizeof(realtype));
|
|
1171
1227
|
|
|
1172
1228
|
/*
|
|
1173
1229
|
* Logging
|
|
1174
1230
|
*/
|
|
1175
1231
|
|
|
1176
1232
|
/* Logging configured? */
|
|
1177
|
-
model->
|
|
1233
|
+
model->logging_initialized = 0;
|
|
1178
1234
|
model->n_logged_variables = 0;
|
|
1179
1235
|
|
|
1180
1236
|
/* Logged variables and logged types */
|
|
@@ -1194,9 +1250,8 @@ for i, expr in enumerate(s_independents):
|
|
|
1194
1250
|
* Default values
|
|
1195
1251
|
*/
|
|
1196
1252
|
|
|
1197
|
-
/* Bound variables */
|
|
1253
|
+
/* Bound variables (except pacing) */
|
|
1198
1254
|
model->time = 0;
|
|
1199
|
-
model->pace = 0;
|
|
1200
1255
|
model->realtime = 0;
|
|
1201
1256
|
model->evaluations = 0;
|
|
1202
1257
|
|
|
@@ -1222,10 +1277,10 @@ for eq in parameters.values():
|
|
|
1222
1277
|
return NULL;
|
|
1223
1278
|
}
|
|
1224
1279
|
|
|
1225
|
-
/*
|
|
1280
|
+
/* State values */
|
|
1226
1281
|
<?
|
|
1227
1282
|
for var in model.states():
|
|
1228
|
-
print(tab + v(var) + ' = ' + myokit.float.str(var.
|
|
1283
|
+
print(tab + v(var) + ' = ' + myokit.float.str(var.initial_value(True)) + ';')
|
|
1229
1284
|
?>
|
|
1230
1285
|
/*
|
|
1231
1286
|
* Caching.
|
|
@@ -1238,7 +1293,7 @@ for var in model.states():
|
|
|
1238
1293
|
#endif
|
|
1239
1294
|
|
|
1240
1295
|
/*
|
|
1241
|
-
*
|
|
1296
|
+
* Finalize
|
|
1242
1297
|
*/
|
|
1243
1298
|
|
|
1244
1299
|
/* Set flag to indicate success */
|
myokit/_sim/cmodel.py
CHANGED
|
@@ -5,9 +5,6 @@
|
|
|
5
5
|
# This file is part of Myokit.
|
|
6
6
|
# See http://myokit.org for copyright, sharing, and licensing details.
|
|
7
7
|
#
|
|
8
|
-
from __future__ import absolute_import, division
|
|
9
|
-
from __future__ import print_function, unicode_literals
|
|
10
|
-
|
|
11
8
|
import os
|
|
12
9
|
import traceback
|
|
13
10
|
|
|
@@ -21,7 +18,7 @@ import myokit.pype
|
|
|
21
18
|
SOURCE_FILE = 'cmodel.h'
|
|
22
19
|
|
|
23
20
|
|
|
24
|
-
class CModel
|
|
21
|
+
class CModel:
|
|
25
22
|
"""
|
|
26
23
|
Generates ansi-C code for a model.
|
|
27
24
|
|
|
@@ -35,6 +32,9 @@ class CModel(object):
|
|
|
35
32
|
|
|
36
33
|
``model``
|
|
37
34
|
A :class:`myokit.Model`.
|
|
35
|
+
``pacing_labels``
|
|
36
|
+
A list of ``str`` variable labels, each corresponding to a paced
|
|
37
|
+
variable.
|
|
38
38
|
``sensitivities``
|
|
39
39
|
Either ``None`` or a tuple ``(dependents, independents)``. See
|
|
40
40
|
:class:`myokit.Simulation` for details.
|
|
@@ -76,7 +76,7 @@ class CModel(object):
|
|
|
76
76
|
Constants that depend on literals, but not on parameters.
|
|
77
77
|
|
|
78
78
|
"""
|
|
79
|
-
def __init__(self, model, sensitivities):
|
|
79
|
+
def __init__(self, model, pacing_labels, sensitivities):
|
|
80
80
|
|
|
81
81
|
# Parse sensitivity arguments
|
|
82
82
|
has_sensitivities, dependents, independents = \
|
|
@@ -86,17 +86,15 @@ class CModel(object):
|
|
|
86
86
|
# bother with keywords.
|
|
87
87
|
model.create_unique_names()
|
|
88
88
|
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
#TODO: Think about best way to do this for model re-use with different
|
|
92
|
-
# sets of bound variables... Presumably the model would simply support
|
|
93
|
-
# all bindings used by any of the simulations based on model.h ?
|
|
94
|
-
bound_variables = model.prepare_bindings({
|
|
89
|
+
# Get mapping from variables to C variable names as used in model.h
|
|
90
|
+
labels = {
|
|
95
91
|
'time': 'time',
|
|
96
|
-
'pace': 'pace',
|
|
97
92
|
'realtime': 'realtime',
|
|
98
93
|
'evaluations': 'evaluations',
|
|
99
|
-
}
|
|
94
|
+
}
|
|
95
|
+
for i, label in enumerate(pacing_labels):
|
|
96
|
+
labels[label] = 'pace_values[' + str(i) + ']'
|
|
97
|
+
bound_variables = myokit._prepare_bindings(model, labels)
|
|
100
98
|
|
|
101
99
|
# Get equations in solvable order (grouped by component)
|
|
102
100
|
equations = model.solvable_order()
|
|
@@ -401,7 +399,7 @@ class CModel(object):
|
|
|
401
399
|
""" Generates and returns the model code. """
|
|
402
400
|
|
|
403
401
|
# Get states whose initial value is used in sensivitity calculations
|
|
404
|
-
initials = [p.var().
|
|
402
|
+
initials = [p.var().index() for p in independents
|
|
405
403
|
if isinstance(p, myokit.InitialValue)]
|
|
406
404
|
|
|
407
405
|
# Arguments
|
myokit/_sim/compiler.py
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
# This file is part of Myokit.
|
|
5
5
|
# See http://myokit.org for copyright, sharing, and licensing details.
|
|
6
6
|
#
|
|
7
|
-
from __future__ import absolute_import, division
|
|
8
|
-
from __future__ import print_function, unicode_literals
|
|
9
|
-
|
|
10
7
|
import os
|
|
11
8
|
|
|
12
9
|
import myokit
|
|
@@ -32,7 +29,7 @@ class Compiler(myokit.CModule):
|
|
|
32
29
|
_compiler = None
|
|
33
30
|
|
|
34
31
|
def __init__(self):
|
|
35
|
-
super(
|
|
32
|
+
super().__init__()
|
|
36
33
|
# Create and cache back-end
|
|
37
34
|
Compiler._index += 1
|
|
38
35
|
|