APSIMInitiative / ApsimX

ApsimX is the next generation of APSIM
http://www.apsim.info
Other
137 stars 165 forks source link

Rotation gets stuck in a loop #9128

Open BrianCollinss opened 4 months ago

BrianCollinss commented 4 months ago

What happened?

My goal is to have a rotation which can skip crops if planting criteria are not met (see https://github.com/APSIMInitiative/ApsimX/discussions/9108).

I tested this setup without having the 'Initial' node as well (where Rotation started at 'Fallow1'), but the same happened.

Rotation.zip

What Operating System are you on?

Windows

BrianCollinss commented 3 months ago

Hi @peter-devoil . By any chance, did you get to have a look at this issue? Cheers.

peter-devoil commented 3 months ago

It is possible to create a loop in the rotation that transitions endlessly. The algorithm says "keep making transitions until no more can be performed". If you have a loop between the two fallow states that relies on the "NotPlanted" rules, it will make that transition forever

Sorting this out isn't easy with summary file messages as they get written at the end of the run (which never happens), but using Console.Writeline() and looking at the stdout will give you a clue which tests are involved.

BrianCollinss commented 3 months ago

If you have a loop between the two fallow states that relies on the "NotPlanted" rules, it will make that transition forever

What I struggle to understand is that even if all crops are not planted in one season, the rotation must still continue since at least one crop will be harvested in the future (could be next season or not). I am unsure why this loop gets stuck though. Even if no crop is evet planted, the sim must end in one of the fallows.

peter-devoil commented 3 months ago

I added a print statement to each manager:

image

and when the the system is fallow:

image

and had to kill it. The logic each day is "keep making transitions until no more can be performed".

BrianCollinss commented 3 months ago

Ah ... what is happening!?

The logic each day is "keep making transitions until no more can be performed".

I assumed when no transition is made, APSIM simply moves on to the next day while keeping the current state. Seems I was wrong!

peter-devoil commented 3 months ago

A transition is made from fallow1 to fallow2. Then, it realises that it can transition to fallow1. Then, it realises that it can transition to fallow2....

peter-devoil commented 3 months ago

I usually add an arc that can be traversed one day after the sowing window closes (eg dayIs("11-jun")). It wont trigger at any day other than 11-jun.