You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
developers will often want to send a parameter sweep or similar, for which the first thing that comes to mind will be to use Numpy or PyTorch to create an array of values. This leads (and we have a real bug report for this) people to write:
params = np.arange(100, 9900, 1000)
jobs = []
for p in params:
jobs.append({"runs": 1000, "variables": {"t": p}})
which should have been
params = np.arange(100, 9900, 1000)
jobs = []
for p in params:
jobs.append({"runs": 1000, "variables": {"t": int(p)}})
i.e. the values should have been casted to int.
Becaues the above fails withe error
File "/usr/lib/python3.10/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type int64 is not JSON serializable
and there isn't much indicating which value failed. Even printing such a thing prints
and because in new NumPy versions they call the types just int, even if you do type(variables["t"]) you get int...
You need to do the object.__class__. trick in the json library to get the actual name out.
Interestingly, if you do params = np.arange(100, 9900, 1000, dtype=float) that does work.
I think we should at least add a warning about this in the docs, but maybe also we can verify that the jobs are serializable?
The text was updated successfully, but these errors were encountered:
Mildophin
changed the title
Add validation of the of the job data
Add validation of the job data
Jul 5, 2023
We should warn users and/or validate the jobs data sent in the request as it can fail to send in a confusing manner.
When adding jobs to the request
The jobs can be given values for the variables,
developers will often want to send a parameter sweep or similar, for which the first thing that comes to mind will be to use Numpy or PyTorch to create an array of values. This leads (and we have a real bug report for this) people to write:
which should have been
i.e. the values should have been casted to int.
Becaues the above fails withe error
and there isn't much indicating which value failed. Even printing such a thing prints
and because in new NumPy versions they call the types just
int
, even if you dotype(variables["t"])
you getint
...You need to do the
object.__class__.
trick in the json library to get the actual name out.Interestingly, if you do
params = np.arange(100, 9900, 1000, dtype=float)
that does work.I think we should at least add a warning about this in the docs, but maybe also we can verify that the jobs are serializable?
The text was updated successfully, but these errors were encountered: