Skip to content

Conversation

@dabacon
Copy link
Collaborator

@dabacon dabacon commented Nov 17, 2020

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 in EngineProgram. Here I've also added batch_size for 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

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 17, 2020
Copy link
Collaborator

@95-martin-orion 95-martin-orion left a 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.

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):
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""
if not params_list or len(programs) != len(params_list):
if params_list is None:
params_list = [dict()] * len(programs)
Copy link
Contributor

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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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()
Copy link
Contributor

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().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator Author

@dabacon dabacon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL addressed comments

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()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""
if not params_list or len(programs) != len(params_list):
if params_list is None:
params_list = [dict()] * len(programs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maffoo maffoo added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 23, 2020
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 23, 2020
@CirqBot CirqBot merged commit 8a82825 into quantumlib:master Nov 23, 2020
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Nov 23, 2020
@dabacon dabacon deleted the batchsize branch April 16, 2022 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Makes googlebot stop complaining.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Number of circuits and sweeps must match" -- run_batch

4 participants