Bug in Sci-ODE

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in Sci-ODE

SergeStinckwich
Dear all,

I still have this annoying bug that appears from time to time in Sci-ODE.
I'm using GraphET for visualization.

==============================================================

|solver state system dt beta gamma values stepper diag colors maxTime|
dt := 1.0.
beta := 1.4247.
gamma := 0.14286.
maxTime := 1000.0.
system := ExplicitSystem block: [ :x :t| |c|
     c := Array new: 3.
     c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
     c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
     c at: 3 put: gamma * (x at: 2).
     c
     ].
stepper := RungeKuttaStepper onSystem: system.
solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
state := { 1-1e-6. 1e-6. 0}.
values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
                                                          time: t
stepSize: dt ].
diag := OrderedCollection new.
colors := Array with: Color blue with: Color red with: Color green.
1 to: 3 do: [ :i|
    diag add:
        ((GETLineDiagram new)
            models: (1 to: maxTime+1 by: 1);
            y: [ :x| (values at: x) at: i ];
            color: (colors at: i))
     ].
builder := (GETDiagramBuilder new).
builder compositeDiagram
    xAxisLabel: 'Time in days';
    yAxisLabel: 'Number of Individuals';
    regularAxis;
    diagrams: diag.
builder open.

==============================================================

generate an error because apparently one of values is not a vector but
an integer ...

I add some error handling, in order to visualize when the problem
happens (return 0.0).

==============================================================

|solver state system dt beta gamma values stepper diag colors maxTime|
dt := 1.0.
beta := 1.4247.
gamma := 0.14286.
maxTime := 1000.0.
system := ExplicitSystem block: [ :x :t| |c|
     c := Array new: 3.
     c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
     c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
     c at: 3 put: gamma * (x at: 2).
     c
     ].
stepper := RungeKuttaStepper onSystem: system.
solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
state := { 1-1e-6. 1e-6. 0}.
values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
                                                          time: t
stepSize: dt ].
diag := OrderedCollection new.
colors := Array with: Color blue with: Color red with: Color green.
1 to: 3 do: [ :i|
    diag add:
        ((GETLineDiagram new)
            models: (1 to: maxTime+1 by: 1);
            y: [ :x| [(values at: x) at: i ] on:Exception do: [0.0]];
            color: (colors at: i))
     ].
builder := (GETDiagramBuilder new).
builder compositeDiagram
    xAxisLabel: 'Time in days';
    yAxisLabel: 'Number of Individuals';
    regularAxis;
    diagrams: diag.
builder open.

=========================================================

Apparently every time, I relaunch the computation, the error is not at
the same place ...
I have the same problem with other differential equations.

Any idea what happened Natalia ?

Thank you.
Regards,
--
Serge Stinckwich
UCBN & UMI UMMISCO 209 (IRD/UPMC)
Every DSL ends up being Smalltalk
http://www.doesnotunderstand.org/

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Sci-ODE

Natalia Tymchuk
Hello,
I have just seen this letter. I will try to understand  and answer you tomorrow.
Best regards,
Natalia
On Jul 31, 2014, at 6:10 PM, Serge Stinckwich <[hidden email]> wrote:

> Dear all,
>
> I still have this annoying bug that appears from time to time in Sci-ODE.
> I'm using GraphET for visualization.
>
> ==============================================================
>
> |solver state system dt beta gamma values stepper diag colors maxTime|
> dt := 1.0.
> beta := 1.4247.
> gamma := 0.14286.
> maxTime := 1000.0.
> system := ExplicitSystem block: [ :x :t| |c|
>     c := Array new: 3.
>     c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
>     c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
>     c at: 3 put: gamma * (x at: 2).
>     c
>     ].
> stepper := RungeKuttaStepper onSystem: system.
> solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
> state := { 1-1e-6. 1e-6. 0}.
> values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
>                                                          time: t
> stepSize: dt ].
> diag := OrderedCollection new.
> colors := Array with: Color blue with: Color red with: Color green.
> 1 to: 3 do: [ :i|
>    diag add:
>        ((GETLineDiagram new)
>            models: (1 to: maxTime+1 by: 1);
>            y: [ :x| (values at: x) at: i ];
>            color: (colors at: i))
>     ].
> builder := (GETDiagramBuilder new).
> builder compositeDiagram
>    xAxisLabel: 'Time in days';
>    yAxisLabel: 'Number of Individuals';
>    regularAxis;
>    diagrams: diag.
> builder open.
>
> ==============================================================
>
> generate an error because apparently one of values is not a vector but
> an integer ...
>
> I add some error handling, in order to visualize when the problem
> happens (return 0.0).
>
> ==============================================================
>
> |solver state system dt beta gamma values stepper diag colors maxTime|
> dt := 1.0.
> beta := 1.4247.
> gamma := 0.14286.
> maxTime := 1000.0.
> system := ExplicitSystem block: [ :x :t| |c|
>     c := Array new: 3.
>     c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
>     c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
>     c at: 3 put: gamma * (x at: 2).
>     c
>     ].
> stepper := RungeKuttaStepper onSystem: system.
> solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
> state := { 1-1e-6. 1e-6. 0}.
> values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
>                                                          time: t
> stepSize: dt ].
> diag := OrderedCollection new.
> colors := Array with: Color blue with: Color red with: Color green.
> 1 to: 3 do: [ :i|
>    diag add:
>        ((GETLineDiagram new)
>            models: (1 to: maxTime+1 by: 1);
>            y: [ :x| [(values at: x) at: i ] on:Exception do: [0.0]];
>            color: (colors at: i))
>     ].
> builder := (GETDiagramBuilder new).
> builder compositeDiagram
>    xAxisLabel: 'Time in days';
>    yAxisLabel: 'Number of Individuals';
>    regularAxis;
>    diagrams: diag.
> builder open.
>
> =========================================================
>
> Apparently every time, I relaunch the computation, the error is not at
> the same place ...
> I have the same problem with other differential equations.
>
> Any idea what happened Natalia ?
>
> Thank you.
> Regards,
> --
> Serge Stinckwich
> UCBN & UMI UMMISCO 209 (IRD/UPMC)
> Every DSL ends up being Smalltalk
> http://www.doesnotunderstand.org/
>
> --
> You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Sci-ODE

Natalia Tymchuk
Hello.
 
The method #doStep:time:stepSize: returns right values and it assigns the right value to state. I don't know why the block returns on some step the integer, but if you write
values := (0.0 to: maxTime by: dt) collect: [ :t|
        state := stepper doStep: state time: t stepSize: dt.
        state ].
it works and plots the diagram. So the problem isn't in ODE. Maybe we should report about this problem to pharo-dev.

Best regards,
Natalia
On Jul 31, 2014, at 7:22 PM, Natalia Tymchuk <[hidden email]> wrote:

> Hello,
> I have just seen this letter. I will try to understand  and answer you tomorrow.
> Best regards,
> Natalia
> On Jul 31, 2014, at 6:10 PM, Serge Stinckwich <[hidden email]> wrote:
>
>> Dear all,
>>
>> I still have this annoying bug that appears from time to time in Sci-ODE.
>> I'm using GraphET for visualization.
>>
>> ==============================================================
>>
>> |solver state system dt beta gamma values stepper diag colors maxTime|
>> dt := 1.0.
>> beta := 1.4247.
>> gamma := 0.14286.
>> maxTime := 1000.0.
>> system := ExplicitSystem block: [ :x :t| |c|
>>    c := Array new: 3.
>>    c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
>>    c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
>>    c at: 3 put: gamma * (x at: 2).
>>    c
>>    ].
>> stepper := RungeKuttaStepper onSystem: system.
>> solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
>> state := { 1-1e-6. 1e-6. 0}.
>> values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
>>                                                         time: t
>> stepSize: dt ].
>> diag := OrderedCollection new.
>> colors := Array with: Color blue with: Color red with: Color green.
>> 1 to: 3 do: [ :i|
>>   diag add:
>>       ((GETLineDiagram new)
>>           models: (1 to: maxTime+1 by: 1);
>>           y: [ :x| (values at: x) at: i ];
>>           color: (colors at: i))
>>    ].
>> builder := (GETDiagramBuilder new).
>> builder compositeDiagram
>>   xAxisLabel: 'Time in days';
>>   yAxisLabel: 'Number of Individuals';
>>   regularAxis;
>>   diagrams: diag.
>> builder open.
>>
>> ==============================================================
>>
>> generate an error because apparently one of values is not a vector but
>> an integer ...
>>
>> I add some error handling, in order to visualize when the problem
>> happens (return 0.0).
>>
>> ==============================================================
>>
>> |solver state system dt beta gamma values stepper diag colors maxTime|
>> dt := 1.0.
>> beta := 1.4247.
>> gamma := 0.14286.
>> maxTime := 1000.0.
>> system := ExplicitSystem block: [ :x :t| |c|
>>    c := Array new: 3.
>>    c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
>>    c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
>>    c at: 3 put: gamma * (x at: 2).
>>    c
>>    ].
>> stepper := RungeKuttaStepper onSystem: system.
>> solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
>> state := { 1-1e-6. 1e-6. 0}.
>> values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
>>                                                         time: t
>> stepSize: dt ].
>> diag := OrderedCollection new.
>> colors := Array with: Color blue with: Color red with: Color green.
>> 1 to: 3 do: [ :i|
>>   diag add:
>>       ((GETLineDiagram new)
>>           models: (1 to: maxTime+1 by: 1);
>>           y: [ :x| [(values at: x) at: i ] on:Exception do: [0.0]];
>>           color: (colors at: i))
>>    ].
>> builder := (GETDiagramBuilder new).
>> builder compositeDiagram
>>   xAxisLabel: 'Time in days';
>>   yAxisLabel: 'Number of Individuals';
>>   regularAxis;
>>   diagrams: diag.
>> builder open.
>>
>> =========================================================
>>
>> Apparently every time, I relaunch the computation, the error is not at
>> the same place ...
>> I have the same problem with other differential equations.
>>
>> Any idea what happened Natalia ?
>>
>> Thank you.
>> Regards,
>> --
>> Serge Stinckwich
>> UCBN & UMI UMMISCO 209 (IRD/UPMC)
>> Every DSL ends up being Smalltalk
>> http://www.doesnotunderstand.org/
>>
>> --
>> You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
>> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Sci-ODE

SergeStinckwich
On Fri, Aug 1, 2014 at 2:52 PM, Natalia Tymchuk
<[hidden email]> wrote:
> Hello.

Hi Natalia,

> The method #doStep:time:stepSize: returns right values and it assigns the right value to state. I don't know why the block returns on some step the integer, but if you write
> values := (0.0 to: maxTime by: dt) collect: [ :t|
>         state := stepper doStep: state time: t stepSize: dt.
>         state ].
> it works and plots the diagram. So the problem isn't in ODE. Maybe we should report about this problem to pharo-dev.

Nice catch, Nathalia !

If you try, the following expression, it works:

|state values |
values := (1 to: 10000) collect: [ : t| state := { t. t+1. t+2.}].
(1 to: 10000) do:[:i | (values at:i) at:2].

and you do more iterations, there is a problem:

|state values |
values := (1 to: 100000) collect: [ : t| state := { t. t+1. t+2.}].
(1 to: 100000) do:[:i | (values at:i) at:2].

and if you move state variable inside the block, it works again :

| values |
values := (1 to: 100000) collect: [ : t| |state| state := { t. t+1. t+2.}].
(1 to: 100000) do:[:i | (values at:i) at:2].

If will report this problem on pharo-dev.
Thank you Natalia, for taking time to understand the problem.

> Best regards,
> Natalia
> On Jul 31, 2014, at 7:22 PM, Natalia Tymchuk <[hidden email]> wrote:
>
>> Hello,
>> I have just seen this letter. I will try to understand  and answer you tomorrow.
>> Best regards,
>> Natalia
>> On Jul 31, 2014, at 6:10 PM, Serge Stinckwich <[hidden email]> wrote:
>>
>>> Dear all,
>>>
>>> I still have this annoying bug that appears from time to time in Sci-ODE.
>>> I'm using GraphET for visualization.
>>>
>>> ==============================================================
>>>
>>> |solver state system dt beta gamma values stepper diag colors maxTime|
>>> dt := 1.0.
>>> beta := 1.4247.
>>> gamma := 0.14286.
>>> maxTime := 1000.0.
>>> system := ExplicitSystem block: [ :x :t| |c|
>>>    c := Array new: 3.
>>>    c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
>>>    c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
>>>    c at: 3 put: gamma * (x at: 2).
>>>    c
>>>    ].
>>> stepper := RungeKuttaStepper onSystem: system.
>>> solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
>>> state := { 1-1e-6. 1e-6. 0}.
>>> values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
>>>                                                         time: t
>>> stepSize: dt ].
>>> diag := OrderedCollection new.
>>> colors := Array with: Color blue with: Color red with: Color green.
>>> 1 to: 3 do: [ :i|
>>>   diag add:
>>>       ((GETLineDiagram new)
>>>           models: (1 to: maxTime+1 by: 1);
>>>           y: [ :x| (values at: x) at: i ];
>>>           color: (colors at: i))
>>>    ].
>>> builder := (GETDiagramBuilder new).
>>> builder compositeDiagram
>>>   xAxisLabel: 'Time in days';
>>>   yAxisLabel: 'Number of Individuals';
>>>   regularAxis;
>>>   diagrams: diag.
>>> builder open.
>>>
>>> ==============================================================
>>>
>>> generate an error because apparently one of values is not a vector but
>>> an integer ...
>>>
>>> I add some error handling, in order to visualize when the problem
>>> happens (return 0.0).
>>>
>>> ==============================================================
>>>
>>> |solver state system dt beta gamma values stepper diag colors maxTime|
>>> dt := 1.0.
>>> beta := 1.4247.
>>> gamma := 0.14286.
>>> maxTime := 1000.0.
>>> system := ExplicitSystem block: [ :x :t| |c|
>>>    c := Array new: 3.
>>>    c at: 1 put: (beta negated) * (x at: 1) * (x at: 2).
>>>    c at: 2 put: (beta * (x at: 1) * (x at: 2)) - (gamma * (x at: 2)).
>>>    c at: 3 put: gamma * (x at: 2).
>>>    c
>>>    ].
>>> stepper := RungeKuttaStepper onSystem: system.
>>> solver := (ExplicitSolver new) stepper: stepper; system: system; dt: dt.
>>> state := { 1-1e-6. 1e-6. 0}.
>>> values := (0.0 to: maxTime by: dt) collect: [ :t| state := stepper doStep: state
>>>                                                         time: t
>>> stepSize: dt ].
>>> diag := OrderedCollection new.
>>> colors := Array with: Color blue with: Color red with: Color green.
>>> 1 to: 3 do: [ :i|
>>>   diag add:
>>>       ((GETLineDiagram new)
>>>           models: (1 to: maxTime+1 by: 1);
>>>           y: [ :x| [(values at: x) at: i ] on:Exception do: [0.0]];
>>>           color: (colors at: i))
>>>    ].
>>> builder := (GETDiagramBuilder new).
>>> builder compositeDiagram
>>>   xAxisLabel: 'Time in days';
>>>   yAxisLabel: 'Number of Individuals';
>>>   regularAxis;
>>>   diagrams: diag.
>>> builder open.
>>>
>>> =========================================================
>>>
>>> Apparently every time, I relaunch the computation, the error is not at
>>> the same place ...
>>> I have the same problem with other differential equations.
>>>
>>> Any idea what happened Natalia ?
>>>
>>> Thank you.
>>> Regards,
>>> --
>>> Serge Stinckwich
>>> UCBN & UMI UMMISCO 209 (IRD/UPMC)
>>> Every DSL ends up being Smalltalk
>>> http://www.doesnotunderstand.org/
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
>>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.



--
Serge Stinckwich
UCBN & UMI UMMISCO 209 (IRD/UPMC)
Every DSL ends up being Smalltalk
http://www.doesnotunderstand.org/

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.