qiskit-community / qiskit-dynamics

Tools for building and solving models of quantum systems in Qiskit
https://qiskit-community.github.io/qiskit-dynamics/
Apache License 2.0
106 stars 60 forks source link

Refactor helper function for setting up list simulation #115

Closed DanPuzzuoli closed 2 years ago

DanPuzzuoli commented 2 years ago

Summary

Refactors some of the logic of the internal function setup_simulation_lists in solver_classes.py into a function setup_args_lists in solver_utils.py, so that it can be reused elsewhere (e.g. it is needed in #73 for setting up list simulation in the new solvers introduced there).

Details and comments

setup_simulation_lists supports the functionality for allowing a user to pass one or more of t_span, y0, and signals as lists to Solver.solve, so that multiple simulations can be run with a single call. This consists of two parts:

The first part of the above is naturally tied to the specifics of the arguments t_span, y0, and signals, however the second part is not, and this is what has been refactored into setup_args_lists to work for an arbitrary number of input arguments. This function takes in a list of arguments, a list of names of those arguments, and a list of functions for validating whether or not the argument is a "valid single input" or a list of "valid single inputs". It applies these functions to all of the arguments, and performs the second part above.

This allows the user to construct more functions like setup_simulation_lists by only needing to supply the list conversion/validation functions.