Method interface¶
A method is the smallest unit of execution within a workflow. Methods are packaged as executables within a Docker image. This doc will tell you how to consume the inputs, produce the outputs, and report method artifacts (progress, errors, and logs).
Request¶
Method run starts by creating a Docker container. Inside a container, the
system prepares a request.json that contains input data and configuration.
Configuration follows the configurationSchema specified in the .method.kts
file. Input data follows the dataInterface's input declarations in the
*.method.kts. Input data is written inside the working directory alongside
request.json. Paths to input data are specified in request.json.
Your executable will likely start by reading the request.json file and
deserializing it into the generated <YourMethodName>RunRequestModel data
class (struct).
Example¶
For a .method.kts that contains the following:
dataInterface {
input("testInput", "simscale.test:test-schema:1.0.0") { label("Test input") }
...
}
configurationSchema {
dimensionalScalar("speed", metricUnits = UnitProfile(default = METER_PER_SECOND))
}
An example request.json will look like this:
{
"configuration": {
"speed": {
"value": 10.0,
"unit": "m/s"
}
},
"dataMap": {
"testInput": {
"path": "/path/to/input/data"
}
}
}
configuration field contains speed, which is the only field in the example
schema. dataMap contains testInput and the associated path.
Response¶
Method run ends by writing a response.json. response.json contains paths
to all output data and can declare each file's MIME type as contentType.
Your executable will likely end by creating an object of
<YourMethodName>RunResponseModel, serialize it, and write it to
response.json in the working directory you started in.
After your executable exits successfully (with exit code 0), the system will
pick up response.json and upload all the output data to internal storage.
Example¶
For a .method.kts that contains the following:
An example response.json might look like this:
There is only testOutput entry because that is the only output. path field
points to your output file.
Methods should declare the MIME type of each output file, for example
application/json, text/csv, or text/plain. The platform stores this
information with the uploaded file so consumers can interpret it. A filename
extension alone does not populate the stored content type.
In generated Python models, set content_type on the output entry and
serialize the response with by_alias=True to write contentType. For
parametric outputs, set it on each file's entry in
parameter_value_combinations. The field is optional for compatibility with
existing methods; omitting it can prevent readers from recognizing the file.
Input/output data¶
Optional data¶
Both inputs and outputs can be declared as optional:
dataInterface {
input("testOptionalInput", "simscale.test:test-schema:1.0.0") { optional = true }
output("testMandatoryOutput", "simscale.test:test-schema:1.0.0") { optional = false }
}
Optional input may or may not be present in request.json when your method
runs. The workflow runner waits with the operation while an upstream operation
that produces the mapped data is still pending, so an optional input fed by
another operation arrives before your method starts. The input is absent when
the workflow definition maps nothing to it, when the mapped workflow input was
not provided, or when the producing operation finished without producing that
data. Optional inputs can be used for modeling restarts from a paused or
previous simulation.
Your method has to declare at least one mandatory output. The system checks
whether all mandatory outputs are provided in the response.json after
execution. Optional outputs might not be provided.
Special data types¶
There are a few data types that deserve special mention:
- simscale.std.cad:cad-model:1.2.0,
- simscale.ramps:ramps-mesh:1.0.0,
- simscale.ramps:ramps-mesh-and-fields:1.0.0,
- simscale.std.table:table:1.1.0.
These are SimScale proprietary formats that describe a CAD model, a mesh and solution fields, and table data. SimScale has built optimized representation for these data types given their central role in the simulation industry.
cad-model is often used as an input. You will interact with the CAD model
via cadlib, which loads the model and runs geometry queries on it
(volume, bounding box, tessellation, …). See
Query a CAD model with cadlib.
ramps-mesh represents a mesh, whereas ramps-mesh-and-fields represents
mesh and fields. You will interact with the mesh and fields via
ramps and
mint.
ramps stands for Result And Mesh Persistent Storage, whereas mint
stands for Mesh INTerface. ramps contains lower level interface for building
mesh and fields, whereas mint contains a higher-level interface for
converting mesh and fields from one format to another
(e.g. VTK → RAMPS → VTK).
table represents any form of tabular data. You will read and write tables
via method-lib.
These data types should be declared as EXTERNAL since they have dedicated,
optimized treatment compared to the rest (INTERNAL data). You can declare
data as EXTERNAL in the *.method.kts file, dataInterface section:
import com.simscale.workflows.framework.data.DataProviderType
...
dataInterface {
output("simulationResults", "simscale.ramps:ramps-mesh-and-fields:1.0.0") {
label("SimScale mesh and fields")
dataProviderType = DataProviderType.EXTERNAL
}
}
For EXTERNAL input data, you will get a string reference in request.json
(instead of path). The reference uniquely represents the corresponding data:
- cad-model → cad-model.cad-id:<uuid>|cad-model.state-id:<uuid>. CAD model
is defined with CAD ID and state ID.
- ramps-mesh → <uuid>. RAMPS mesh is defined with a single mesh UUID.
- ramps-mesh-and-fields → <uuid>. RAMPS mesh and fields are defined with
a single result UUID.
For EXTERNAL output data, you will need to fill in reference field in
response.json instead of path.
Reporting artifacts¶
Method artifacts should be reported via
method-lib's FileSystemArtifactReporter interface.
The interface contains the following functions:
* progress → Reports numerical progress as a percentage from 0 to 100.
* message → Reports a message of different severity to the user. You can
report multiple INFO and WARNING messages, but you should report only
one (terminal) ERROR message.
* log → User-visible method log.
Method artifacts are reported via responseJournal.jsonl file in the working
directory. It is advised not to create, delete, or modify it manually.