Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trap variable is not found with BMI #271

Closed
MostafaGomaa93 opened this issue Dec 5, 2024 · 11 comments · Fixed by #273
Closed

Trap variable is not found with BMI #271

MostafaGomaa93 opened this issue Dec 5, 2024 · 11 comments · Fixed by #273

Comments

@MostafaGomaa93
Copy link
Contributor

MostafaGomaa93 commented Dec 5, 2024

I made a new branch with one small edit (adding the Trap variable to BMI list here). I asked @Crystal-szj to make a new executable file using the Surf machine, but when I tested the new exe in the BMI notebook. I received this error.

BMI_error

The error says the Trap variable is not found, so this refers to the discussion that we had last time. We made a new exe but seems the code changes are not recognized in this new exe.

@BSchilperoort
Copy link
Contributor

How are you running the model, I assume on your local machine with Docker? Because then you need to build a new container image with the MATLAB executable file.

@MostafaGomaa93
Copy link
Contributor Author

MostafaGomaa93 commented Dec 5, 2024

How are you running the model, I assume on your local machine with Docker? Because then you need to build a new container image with the MATLAB executable file.

I run it on the ITC server and not using Docker. Usually, I run on the same machine and always the new exe is okay when @SarahAlidoost makes the new exe.

So there could be something we miss in how to make the new exe

@SarahAlidoost
Copy link
Member

SarahAlidoost commented Dec 5, 2024

How are you running the model, I assume on your local machine with Docker? Because then you need to build a new container image with the MATLAB executable file.

I run it on the ITC server and not using Docker. Usually, I run on the same machine and always the new exe is okay when @SarahAlidoost makes the new exe.

So there could be something we miss in how to make the new exe

@MostafaGomaa93 From your screenshot, I see that the BMI interface returns the error "variable 'Trap' not found". This is not related to exe file but because this variable is not initialized in the code. You only added this variable to the STEMMUS_SCOPE_exe but not the initialize part of STEMMUS_SCOPE. If you want to add any variable to BMI, it should be initialized. This can be added as Trap =[]; after this line, similar to RWUg. After adding this change, can you please make the exe again and check if it works?

@MostafaGomaa93
Copy link
Contributor Author

MostafaGomaa93 commented Dec 5, 2024

Thanks @SarahAlidoost. After your suggestion and with the new exe, the error is gone but the Trap value in BMI is always zero. I check the shape of the Trap. It is a matrix like (1, n_timesteps) which is filled in with the value per every time step and

at KT = 1 -> Trap = 0
at KT = 2 -> Trap = 0 0.007
at KT = 3 -> Trap = 0 0 0.008

@BSchilperoort
I did two trials (try 1, try 2) with different shapes to get the values but still, the value was not picked. Any suggestion?
make an empty array to store values
Trap = np.zeros((1, n_timesteps)) # try 1
Trap = np.zeros(1) # try 2

then get the value
model.get_value("transpiration_total", Trap)

Just to confirm, I worked on my local branch for STEMMUS_SCOPE_Processing in which I add the Trap to the variable_reference.py file

@BSchilperoort
Copy link
Contributor

The BmiVariable in PyStemmusScope needs the all_timesteps=True argument.

@MostafaGomaa93
Copy link
Contributor Author

MostafaGomaa93 commented Dec 5, 2024

The BmiVariable in PyStemmusScope needs the all_timesteps=True argument.

I am adding it already but still zero

    BmiVariable(
    name="transpiration_total",
    dtype="float64",
    input=False,
    output=True,
    units="cm s-1",
    grid=0,
    keys=["Trap"],
    all_timesteps=True,
),

@SarahAlidoost
Copy link
Member

The BmiVariable in PyStemmusScope needs the all_timesteps=True argument.

I am adding it already but still zero

    BmiVariable(
    name="transpiration_total",
    dtype="float64",
    input=False,
    output=True,
    units="cm s-1",
    grid=0,
    keys=["Trap"],
    all_timesteps=True,
),

can you please commit your change and push it to add_rainfall_to_bmi?

@MostafaGomaa93
Copy link
Contributor Author

can you please commit your change and push it to add_rainfall_to_bmi?

Done

@SarahAlidoost
Copy link
Member

Thanks @SarahAlidoost. After your suggestion and with the new exe, the error is gone but the Trap value in BMI is always zero. I check the shape of the Trap. It is a matrix like (1, n_timesteps) which is filled in with the value per every time step and

at KT = 1 -> Trap = 0 at KT = 2 -> Trap = 0 0.007 at KT = 3 -> Trap = 0 0 0.008

I just saw this. The size of the variable Trap changes while the model runs, which is not compatible with BMI. To fix this, Trap should either always have a size of 1 or match the size of all time steps. Having a size of 1 is preferred, like the variable RWUg. Right now, though, this isn’t happening because Trap size keeps changing. Here is a list of changes to fix the issue:

  • remove this line
  • replace Trap in this line with Tp_t
  • add Tp_t=0; before this if block to make sure that it has a default value.
  • rename Tp_t with a clear name
  • replace Trap(k) in this line with Trap as it is now just one value.
  • remove all_timesteps=True from bmi variables.

@MostafaGomaa93
Copy link
Contributor Author

Many thanks, @SarahAlidoost, I implement them in this PR.

@MostafaGomaa93
Copy link
Contributor Author

I also checked the new exe and it works okay. Now both Evap and Trap are 1 size array and give value in BMI

@MostafaGomaa93 MostafaGomaa93 changed the title Executable is not recognizing the code changes Trap variable is not found with BMI Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants