RatInABox-Lab / RatInABox

A python package for modelling locomotion in complex environments and spatially/velocity selective cell activity.
MIT License
172 stars 31 forks source link

add error checking to parameter settings #107

Closed ZilongJi closed 3 months ago

ZilongJi commented 3 months ago

Hi there,

I am using the develop version of RatInABox (maybe this won't be an issue in the normal version).

It will be nice to add error check in parameter settings. For example, in generating trajectories with different tortuosity:

Ag = Agent(Env, params = { "rotation_velocity_std": 60 * (np.pi / 180) })

This will not change the tortuosity since the correct param name is "rotational_velocity_std", not "rotation_velocity_std". However, the code will not through out an error for that.

TomGeorge1234 commented 3 months ago

It should throw a warning but not an error. Which version are you using, this was effectively solved in v1.5.1 by #38 and #39. (Because we're using dictionaries not arguments it's harder to check if a parameter is wrong as you have noticed - the current solution is to check the class and up through all its parents to collect all default_params and throw a warning if your param isn't amongst these. The reason we do warning not errors is that, in theory, you could have made child class of, say,Agent, which takes extra parameters which you didn't provide in a default_params dictionary. This is getting in to the weeds a bit but if you feel strongly for errors over warnings let me know why.)

Here's my example:

Env = Environment()
Ag = Agent(Env, params={"rotation_velocity_std":60})

which throws

UserWarning: Found 1 unexpected params key(s) while initializing Agent object: 'rotation_velocity_std'.
If you intended to set this parameter, ignore this message. To see all default parameters for this class call Agent.get_all_default_params().
  warnings.warn(
ZilongJi commented 3 months ago

I see! Thanks for the clear explanation! I do get the warning but I ignored. Sorry for that.