Skip to content

Conversation

@chriseclectic
Copy link
Collaborator

@chriseclectic chriseclectic commented Mar 1, 2022

Summary

This adds a _finalize method to BaseExperiment called in run before the actual experiment is run which gives users a hook for setting any custom experiment or option values based on the final configuration of the experiment before execution.

Details and comments

The main goal for this is to allow developers/users to be able to set automatically calculated experiment or analysis option values that might depend on a combination of other option values when writing an experiment subclass. For example it could be used to configure a specific data processor in analysis based on the backend and run option values (@eggerdj), or to set the initial guess value for CR hamiltonian in #695 (@nkanazawa1989)

@eggerdj
Copy link
Contributor

eggerdj commented Mar 2, 2022

This looks like a nice addition. It might also help us implement restless measurements which require a modified data processor based on the run options. See e.g. #689. @chriseclectic aside from the code, is there a place that describes the workflow of the base experiment (e.g. a flow chart showing the conceptual steps) that also contains all the possible hooks?

One question: how does this work with parallel experiments?

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

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

This looks good to me. To add extra metadata to transpiled circuit as done in the standard RB experiment, a subclass still need to override _transpiled_circuits method rather than passing circuits to this method?

(EDIT)
Probably this can be called before _transpiled_circuits since some experiment may want to override transpile options?

@chriseclectic
Copy link
Collaborator Author

@eggerdj Good point for composite experiments. I believe that should work correctly if composite experiment implements a finalize method that recursively calls finalize for each sub-experiment and that composite experiment set_run_options is updated to recursively set run options in each sub-experiment.

This adds a `_finalize` method to BaseExperiment called in run before the actual experiment is run which gives users a hook for setting any custom experiment or option values based on the final configuration of the experiment before execution.
These options are now recursively set during  when setting an experiments run options. Note that all this job metadata is planned to be removed asap.
@chriseclectic chriseclectic changed the title [RFC] Add BaseExperiment._finalize method Add BaseExperiment._finalize method Mar 3, 2022
Move the validation that sub experiments did not explicitly set custom run options different from the parent experiment into composite experiment _finalize method.
@chriseclectic chriseclectic added the Changelog: New Feature Include in the "Added" section of the changelog label Mar 3, 2022
@chriseclectic chriseclectic merged commit 53c3d21 into qiskit-community:main Mar 3, 2022
paco-ri pushed a commit to paco-ri/qiskit-experiments that referenced this pull request Jul 11, 2022
Adds a `_finalize` method to BaseExperiment called in run before the actual experiment is run which gives users a hook for setting any custom experiment or option values based on the final configuration of the experiment before execution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: New Feature Include in the "Added" section of the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants