-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixes run_batch requiring param list #3507
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
Conversation
95-martin-orion
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that deprecation is unnecessary here. One nit and this is ready to merge.
cirq/google/engine/engine.py
Outdated
| if not params_list or len(programs) != len(params_list): | ||
| if params_list is None: | ||
| params_list = [dict()] * len(programs) | ||
| if len(programs) != len(params_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line above ensures params_list and programs are of equal length, so this if can be an elif.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cirq/google/engine/engine.py
Outdated
| """ | ||
| if not params_list or len(programs) != len(params_list): | ||
| if params_list is None: | ||
| params_list = [dict()] * len(programs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do [None] * len(programs) since cirq.Sweepable includes None (via ParamResolverOrSimilarType).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cirq/google/engine/engine_program.py
Outdated
| if self.result_type != ResultType.Batch: | ||
| raise ValueError('Can only use run_batch() in batch mode.') | ||
| if params_list is None: | ||
| params_list = [dict()] * self.batch_size() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, too, can do [None] * self.batch_size().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dabacon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL addressed comments
cirq/google/engine/engine_program.py
Outdated
| if self.result_type != ResultType.Batch: | ||
| raise ValueError('Can only use run_batch() in batch mode.') | ||
| if params_list is None: | ||
| params_list = [dict()] * self.batch_size() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cirq/google/engine/engine.py
Outdated
| """ | ||
| if not params_list or len(programs) != len(params_list): | ||
| if params_list is None: | ||
| params_list = [dict()] * len(programs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cirq/google/engine/engine.py
Outdated
| if not params_list or len(programs) != len(params_list): | ||
| if params_list is None: | ||
| params_list = [dict()] * len(programs) | ||
| if len(programs) != len(params_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
maffoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In #3285 it points out that there is a requirement that there always be param lists specified for a batch program on
Engine.run_batch. This changes this to the sensible default, which is that if the params are None that empty param sweeps are sent to match the programs. This also required changes to the similar calls inEngineProgram. Here I've also addedbatch_sizefor batch programs, that uses the cached value of the program, or potentially fetches a new program.While this technically changes the api of this method, it only makes it possible to now use the default or specify None, so don't think this needs to got through deprecation.
Fixed #3285