Kappa-Dev / KappaTools

Tool suite for kappa models. Documentation and binaries can be found in the release section. Try it online at
http://kappalanguage.org/
GNU Lesser General Public License v3.0
108 stars 40 forks source link

Mere presence of agent declaration with counters causes incorrect results #683

Closed wwaites closed 6 months ago

wwaites commented 6 months ago

Consider the following model,

%agent: A()

'create'  . -> A() @ 1
'destroy' A() -> . @ 1

%obs: A |A()|

Simulating this behaves as expected: we see a few of A() around:

# Output of 'KaSim' '-l' '1000' 'minimal.ka' -seed 585431695
# "uuid" : "393103961"
"[T]","A"
0.,0
1.,0
2.,0
3.,1
4.,2
5.,1
6.,0
7.,1
8.,2
9.,4

Now modify the model in a way that ought not perturb the simulation at all. Simply add a second agent with a counter,

%agent: A()
%agent: B(c{=0 / += 10})

'create'  . -> A() @ 1
'destroy' A() -> . @ 1

%obs: A |A()|

Simulating that produces the following,

# Output of 'KaSim' '-l' '1000' 'minimal.ka' -seed 347145272
# "uuid" : "883845609"
"[T]","A"
0.,0
1.,2
2.,3
3.,3
4.,4
5.,4
6.,4
7.,4
8.,6
9.,6
10.,6
11.,7
12.,9
13.,12
14.,13
15.,15
16.,15
17.,16
18.,17
19.,17
20.,17

Growing explosively...

wwaites commented 6 months ago

This is with KaSim c27be22 from today, March 9th 2024

feret commented 6 months ago

If you use the following model: %agent: A() %agent: B(c{=0 / += 10}) %agent: C()

'create' . -> A() @ 1 'destroy' A(),. -> .,C() @ 1

%obs: A |A()| %obs: C |C()|

You notice that the rule 'destroy' is never triggered (which is a bug).

feret commented 6 months ago

Same behavior in d2b2c0a9279d631df131a96147c0c3ea4c70ea8e 25 May 2023. Thus, this is not an issue introduced by recent changes.

feret commented 6 months ago

Indeed, the rule is erased. This can be seen easily by using Kasim --compile.

feret commented 6 months ago

Should be fixed by commit d824f946ce4ac76a6393368feeb8f914ac4790e0 Please try.

wwaites commented 6 months ago

I did not know about --compile. Very useful. Yes, this seems fix this problem. Thanks!