APSIMInitiative / ApsimX

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

Cannot run simulations with CroptimizR #8632

Closed KeLiu7 closed 7 months ago

KeLiu7 commented 8 months ago

What happened?

Hi,

I'm trying to use CroptimizR functions to parameterise Wheat LAI and biomass but the simulation does not go through. I can run the examples (CroptimizRExample) in the APSIM Next Gen examples folder but not my own simulation. So I think my docker settings should ok. I have attached the sim file below. Thank you very much! @par456

The error says below.

One or more errors occurred. (Container exited with non-zero exit code. Container log: [1] "----------------------------------------------"
[2] "System.Exception: Error in file:/tmp/RtmpnBL6Vh/apsimOnR129a087ec.apsimx"
[3] " ---> System.Exception: Error reading file /tmp/RtmpnBL6Vh/apsimOnR129a087ec.apsimx"
[4] " ---> System.Exception: Duplicate models found: .Simulations.Replacements.Wheat.Phenology.Germinating has 2 children named MinSoilTemperature"
[5] " at Models.Core.Run.SimulationGroup.<>c.b__29_0(Exception e) in /apsim/Models/Core/Run/SimulationGroup.cs:line 219"
[6] " at Models.Core.ApsimFile.FileFormat.InitialiseModel(IModel newModel, Action1 errorHandler) in /apsim/Models/Core/ApsimFile/FileFormat.cs:line 146" [7] " at Models.Core.ApsimFile.FileFormat.ReadFromString[T](String st, Action1 errorHandler, Boolean initInBackground, String fileName) in /apsim/Models/Core/ApsimFile/FileFormat.cs:line 121" [8] " at Models.Core.ApsimFile.FileFormat.ReadFromFile[T](String fileName, Action1 errorHandler, Boolean initInBackground) in /apsim/Models/Core/ApsimFile/FileFormat.cs:line 62" [9] " --- End of inner exception stack trace ---" [10] " at Models.Core.ApsimFile.FileFormat.ReadFromFile[T](String fileName, Action1 errorHandler, Boolean initInBackground) in /apsim/Models/Core/ApsimFile/FileFormat.cs:line 78"
[11] " at Models.Core.Run.SimulationGroup.Initialise() in /apsim/Models/Core/Run/SimulationGroup.cs:line 219"
[12] " --- End of inner exception stack trace ---"
[13] "ERRORS FOUND!!"
attr(,"status") [1] 1

Learn CroptimizR at: https://SticsRPacks.github.io/CroptimizR

Attaching package: 'CroptimizR'

The following objects are masked from 'package:stats':

AIC, BIC

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

filter, lag

The following objects are masked from 'package:base':

intersect, setdiff, setequal, union

Error: no such table: Dailyreport In addition: Warning message: In system(cmd, wait = TRUE, intern = TRUE) : running command '/opt/apsim/Models /tmp/RtmpnBL6Vh/apsimOnR129a087ec.apsimx' had status 1 Execution halted

)


Wheat test.zip

What Operating System are you on?

Windows

par456 commented 8 months ago

The attached PR should resolve most of your issues. The only other one is that you are referring to Wheat.LAI in several places (DailyReport and CroptimizR) when I think you actually want Wheat.Leaf.LAI which is what you have in the observed file. I made that change with the changes from the PR and was able to run the sim without errors.

KeLiu7 commented 8 months ago

The attached PR should resolve most of your issues. The only other one is that you are referring to Wheat.LAI in several places (DailyReport and CroptimizR) when I think you actually want Wheat.Leaf.LAI which is what you have in the observed file. I made that change with the changes from the PR and was able to run the sim without errors.

Many thanks. I will try again once this PR is merged😊

KeLiu7 commented 8 months ago

Hi @par456, My example still does not go through. The Error says"The process cannot access the file 'input_file.db' because it is being used by another process." Could you please help me check the problem? Many thanks. Test.zip

par456 commented 8 months ago

That generally happens if the directory you are working in is a OneDrive (or similar) directory. Apsim is trying to read or write to the database and the syncronsing software is holding it open as it tries to copy the file. Just check that you don't have one of those running at all, then restart apsim and try it again.

If it's still happening, I'll have to look a bit further.

KeLiu7 commented 8 months ago

I'm running the example sims on the directory (E:\AgMIP-Waterlogging\Sensitivity results\AgMIP - Waterlogging - Inputs-20231206T143214Z-001\AgMIP - Waterlogging - Inputs\Ex1_a\New folder) not OneDrive.

I quit my University Onedrive and tested again but the same error still existed. I also changed the directory to another drive also not work...

I'm running the example sims on the directory (E:\AgMIP-Waterlogging\Sensitivity results\AgMIP - Waterlogging - Inputs-20231206T143214Z-001\AgMIP - Waterlogging - Inputs\Ex1_a\New folder) not OneDrive.

I quit my University Onedrive and tested again but the same error still existed. I also changed the directory to another drive also not work...

The GUI interface is displayed as follows. image

Detailed information is below

System.IO.IOException: The process cannot access the file 'input_file.db' because it is being used by another process. at System.IO.FileSystem.RemoveDirectoryRecursive(String fullPath, WIN32_FIND_DATA& findData, Boolean topLevel) at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive) at Models.Optimisation.CroptimizR.Run(CancellationTokenSource cancelToken) in C:\Users\ContainerAdministrator\AppData\Local\Temp\ApsimX\Models\Optimisation\CroptimizR.cs:line 523 at APSIM.Shared.JobRunning.JobRunner.Run(IRunnable job) in C:\Users\ContainerAdministrator\AppData\Local\Temp\ApsimX\APSIM.Shared\JobRunning\JobRunner.cs:line 226 at APSIM.Shared.JobRunning.JobRunner.RunActualJob(IRunnable job, IJobManager jobManager) in C:\Users\ContainerAdministrator\AppData\Local\Temp\ApsimX\APSIM.Shared\JobRunning\JobRunner.cs:line 189

Some optimization results are obtained, but they are not normal. image

par456 commented 8 months ago

I've only got a Linux system here to test croptimiR with today, and it ran fine for me, so this may be a Windows specific problem. I'll reopen and have a look when I can. This was the output I got if you want to check that it has run correctly.

TestAfterRun.zip

KeLiu7 commented 8 months ago

I've only got a Linux system here to test croptimiR with today, and it ran fine for me, so this may be a Windows specific problem. I'll reopen and have a look when I can. This was the output I got if you want to check that it has run correctly.

TestAfterRun.zip

Thanks Andrew. I just compared my results with yours-thy are completely identical. Just not sure why GUI shows errors when the simulation is finished...

par456 commented 7 months ago

Just ran this on the latest build on a windows machine that could do croptimizeR and it ran without problem. So not sure what was causing the error on yours, but it seems to be right here now.

Closing unless it pops up again.