Hopsan
|
The Hopsan CLI (Command Line Interface) is an application that you can use to simulate Hopsan models from the command line. The CLI has a number of options that let you load models, import/export parameter sets, export the simulation results and run tests. The CLI can be called from external programs or scripts. This is useful if you want to run batch tests or if you want to run Hopsan simulations from an external application that do not have "co-simulation" or "export" support in Hopsan.
The Hopsan CLI can be used to simulate existing models, but you cannot create models with the CLI. Use the HopsanGUI application for that.
The HopsanCLI is located in the \bin
folder of your Hopsan installation. By calling hopsancli --help
you will get help output showing you all the options. The help text is also given here for your convenience, but be sure to check the actual help since this manual page may not always be up-to-date.
USAGE: ./hopsancli [-m <Path to file>] [-e <Path to file>] ... [--externalLibsFile <Path to file>] [-s <Comma separated string>] [-l <integer>] [-t <Path to .hvc file>] [--parameterImport <Path to file>] [--parameterExport <Path to file>] [--resultsFullCSV <Path to file>] [--resultsFinalCSV <Path to file>] [--resultsCSVSort <string>] [--loadSimState <string>] [--saveSimState <string>] [-d <Path to directory>] [--buildComponentLibrary <string>] [--prefixRootSystemName] [--createValidationData] [--printDebug] [--endPause] [--testInstanciateComponents] [--] [--version] [-h] Where: -m <Path to file>, --hmf <Path to file> The Hopsan model file to load -e <Path to file>, --externalLib <Path to file> (accepted multiple times) Path to a .dll/.so/.dylib externalComponentLib. Can be given multiple times --externalLibsFile <Path to file> A text file containing the external libs to load -s <Comma separated string>, --simulate <Comma separated string> Specify simulation time as: [hmf] or [start,ts,stop] or [ts,stop] or [stop] -l <integer>, --numLogSamples <integer> Set the number of log samples to store for the top-level system, (default: Use number in .hmf) -t <Path to .hvc file>, --validate <Path to .hvc file> Perform model validation based on HopsanValidationConfiguration --parameterImport <Path to file> CSV file with parameter values to import --parameterExport <Path to file> CSV file with exported parameter values --resultsFullCSV <Path to file> Export the results (all logged data) --resultsFinalCSV <Path to file> Export the results (only final values) --resultsCSVSort <string> Export results in columns or in rows: [rows, cols] --loadSimStartValues <string> Load the start values (simulation state without time offset) from this file --loadSimState <string> Load the simulation state (with time offset) from this file --saveSimState <string> Export the simulation state to this file -d <Path to directory>, --destination <Path to directory> Destination for resulting files --buildComponentLibrary <string> Build the specified component library (point to the library xml) --prefixRootSystemName Prefix the root-level system name to exported results and parameters --createValidationData Create a model validation data set based on the variables connected to scopes in the model given by option -m --printDebug Show debug messages in the output --endPause Pauses the CLI at the end to let you see its output --testInstanciateComponents Create an instance of each registered component to look for errors. --, --ignore_rest Ignores the rest of the labeled arguments following this flag. --version Displays version information and exits. -h, --help Displays usage information and exits.
Some run command examples:
These examples use MS Windows filename syntax. (On Linux you should use forward / instead of backslash)
hopsancli -m "path_to\MyModel.hmf" -s hmf --resultsFullCSV myFullLogdata.csv
This will simulate a model using the simulation time set in the model file and exports the entire logdata set to a CSV format file
hopsancli -m "path_to\MyModel.hmf" -s -1,0.001,10 --resultsFinalCSV myFinalLogdata.csv
This will simulate a model using specified simulation time startT,Ts,stopT and exports the final values from the logdata set to a CSV format file
hopsancli -m "path_to\MyModel.hmf" --parameterExport myModelParameters.csv
This will export the parameters from the model in a CSV file format. The model will not be simulated.
hopsancli -m "path_to\MyModel.hmf" --parameterImport myModelNewParameters.csv -s 0,0.001,10 --resultsFinalCSV myFinalLogdata.csv
This will import the parameters from a csv file (same format as exported in the previous command example) and simulate the model using the specified parameter values. (This is useful when calling models from external programs if you want to change parameters. For instance, usually when running external optimization.
hopsancli -m "path_to\MyModel.hmf" -e "somePathTo\myCompLib1.dll" -e "someOtherPathTo\myCompLib2.dll" -s hmf --resultsFullCSV myFullLogdata.csv
This will load your model and two external component libraries, then simulate and export the results.
hopsancli -t "somePathTo\myModelValidation.hvc"
This will load a model validation configuration file and run the validation tests. Text will be shown whether the tests pass or fail. The Hopsan CLI return value will also reflect failure or success.