fast-aircraft-design / FAST-OAD

FAST-OAD: An open source framework for rapid Overall Aircraft Design
GNU General Public License v3.0
47 stars 25 forks source link

Specify imports or initial code in the configuration file #413

Open ScottDelbecq opened 2 years ago

ScottDelbecq commented 2 years ago

Is your feature request related to a problem? Please describe. It would be nice to specify some imports or piece of code in the configuration file to be executed before the FAST-OAD process.

Describe the solution you'd like We could imagine something like for example:

title: Sample OAD Process

# List of folder paths where user added custom registered OpenMDAO components
module_folders:

# Input and output files
input_file: ./problem_inputs.xml
output_file: ./problem_outputs.xml

# Python code to be executed
script: >
    import numpy as np
    from mydriver import MyDriver
    maxiter = np.ceil(2022/3)

# Definition of problem driver
driver: MyDriver(tol=1e-2, optimizer='COBYLA', maxiter=maxiter)

Describe alternatives you've considered Of course other key names instead of script, like code.

ScottDelbecq commented 1 year ago

Another need would be to modify the driver options/attributes after instantiation:

prob.driver = om.pyOptSparseDriver(optimizer='SLSQP')

prob.driver.opt_settings['MAXIT'] = 3
christophe-david commented 1 year ago

A possible solution would be to keep the driver parameter for standard uses cases, but to allow the usage of a driver_script that could be used instead for advanced use cases. This new parameter would allow providing a snippet that would have to set the driver and do whatever needed around it (imports, setting options, ...). For that, a convention would be used, that problem would be the instance name to use.

ScottDelbecq commented 8 months ago

For importing additional packages or drivers we could provide the possibility to specify what to import:

title: Sample OAD Process

# List of folder paths where user added custom registered OpenMDAO components
module_folders:

# Input and output files
input_file: ./problem_inputs.xml
output_file: ./problem_outputs.xml

# Imports
imports:
    - my_driver_1: MyDriver1
    - my_driver_2: MyDriver2

# Definition of problem driver
driver: MyDriver1(tol=1e-2, optimizer='COBYLA', maxiter=maxiter)

These imports would be equivalent to:

from my_driver_1 import MyDriver1
from my_driver_2 import MyDriver2