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

Add validation of the job data #57

Open
awennersteen opened this issue Jan 5, 2023 · 0 comments
Open

Add validation of the job data #57

awennersteen opened this issue Jan 5, 2023 · 0 comments

Comments

@awennersteen
Copy link
Member

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

batch = `sdk.create_batch(seq,` device_type="EMU_FREE", jobs=jobs)

The jobs can be given values for the variables,

jobs = [{runs=1000, variables={"my_var": 100}]

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

`jobs':` [{'runs': 1000, 'variables': {'t': 100}}]

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?

@Mildophin Mildophin changed the title Add validation of the of the job data Add validation of the job data Jul 5, 2023
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

No branches or pull requests

1 participant