Skip to content

Improve the inheritance and consistency of trainers #59

@yishaishimoni

Description

@yishaishimoni

What should we add?

The various trainers in this project inherit from BaseTrainer, but have a different signature for their train() function.
This can cause issues at runtime, but more importantly it creates confusion for users regarding how to use each of the trainers.

There are even cases where different trainers require the same input but with a different name (e.g., reps vs. qaoa_depth or params0 vs previous_optimal_point).

There are several ways to address this:

  1. It is possible to define a single minimal set of inputs to train() and make sure that all other parameters are entered at __init__. This is a reasonable solution when the additional parameters really inherently define the trainer and not the specific training run.
  2. Perhaps a set of trainers can be identified that share similar inputs and can then be bunched together in a more coherent inheritance hierarchy. For example, trainers that support initial point can all inherit from a FromInitTrainer (or some other, probably better ;) , name)

Each of these solutions, and even just merging parameters that mean the same with different names, will be backwards incompatible and so require some thought.

Below I provide a table of the parameters each of the classes receives in their train function:

Trainer Class cost_op mixer initial_state ansatz_circuit params0 reps degree folder file_pattern parameter_ranges num_points lower_bound upper_bound seed previous_optimal_point trainer1_kwargs initial_dt qaoa_depth
BaseTrainer - - - - - - - - - - - - -
FixedAngleConjecture ~ ~ ~ ~ - - - - - - - - - - -
OptimizedParametersLoader ~ ~ ~ ~ ~ - - - - - - - - - - -
DepthOneScanTrainer ~ - - - - - - - - - - -
DepthOneGammaScanTrainer ~ ~ - - - - - - - - - - -
QAOAPCA ~ - - - - - - - - - - - - -
RandomPoint ~ ~ ~ ~ ~ - - - - - - - - -
RecursionTrainer - - - - - - - - - - - -
RecursiveTransitionStates ~ - - - - - - - - - - -
ReweightingTrainer - - - - - - - - - - - -
ScipyTrainer ~ - - - - - - - - - - - - -
TQATrainer ~ - - - - - - - - - - -
TransferTrainer x x x ~ - - - - - - - - - - - -
TransitionStatesTrainer ~ - - - - - - - - - - - -

Where

  • ✓ means that the parameter is accepted and used
  • - means that the parameter is not accepted in the API
  • x means that the parameter is accepted in the API but an exception is thrown if actually passed
  • ~ means that the parameter is accepted but not used

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions