88import os
99import unittest
1010import sympy as sp
11+ import libsbml
12+ from tempfile import TemporaryDirectory
13+
1114
1215class TestAmiciMisc (unittest .TestCase ):
1316 """TestCase class various AMICI Python interface functions"""
@@ -47,6 +50,18 @@ def test_csc_matrix(self):
4750 assert symbolList == ['a0' , 'a1' , 'a2' ]
4851 assert str (sparseMatrix ) == 'Matrix([[a0, 0], [a1, a2]])'
4952
53+ def test_csc_matrix_empty (self ):
54+ """Test sparse CSC matrix creation for empty matrix"""
55+ matrix = sp .Matrix ()
56+ symbolColPtrs , symbolRowVals , sparseList , symbolList , sparseMatrix = \
57+ amici .ode_export .csc_matrix (matrix , 'a' )
58+ print (symbolColPtrs , symbolRowVals , sparseList , symbolList , sparseMatrix )
59+ assert symbolColPtrs == [0 ]
60+ assert symbolRowVals == []
61+ assert sparseList == sp .Matrix (0 , 0 , [])
62+ assert symbolList == []
63+ assert str (sparseMatrix ) == 'Matrix(0, 0, [])'
64+
5065 def test_csc_matrix_vector (self ):
5166 """Test sparse CSC matrix creation from matrix slice"""
5267 matrix = sp .Matrix ([[1 , 0 ], [2 , 3 ]])
@@ -70,6 +85,29 @@ def test_csc_matrix_vector(self):
7085 assert symbolList == ['a2' ]
7186 assert str (sparseMatrix ) == 'Matrix([[0], [a2]])'
7287
88+ def test_sbml2amici_no_observables (self ):
89+ """Test model generation works for model without observables"""
90+
91+ document = libsbml .SBMLDocument (3 , 1 )
92+ model = document .createModel ()
93+ model .setTimeUnits ("second" )
94+ model .setExtentUnits ("mole" )
95+ model .setSubstanceUnits ('mole' )
96+ c1 = model .createCompartment ()
97+ c1 .setId ('C1' )
98+ model .addCompartment (c1 )
99+ s1 = model .createSpecies ()
100+ s1 .setId ('S1' )
101+ s1 .setCompartment ('C1' )
102+ model .addSpecies (s1 )
103+
104+ sbml_importer = amici .sbml_import .SbmlImporter (sbml_source = model ,
105+ from_file = False )
106+ tmpdir = TemporaryDirectory ()
107+ sbml_importer .sbml2amici (modelName = "test" ,
108+ output_dir = tmpdir .name ,
109+ observables = None )
110+
73111
74112if __name__ == '__main__' :
75113 suite = unittest .TestSuite ()
0 commit comments