Skip to content

Analyses ​

In Dyad, an analysis is "the things you can do with a model". A typical workflow in Dyad is to create a set of components, and then create an analysis that runs on the entry point to that set of components. It produces a solution object that provides information about the model, and can be used to build various visualizations.

Analyses can perform a wide variety of model analytics, such as:

and much more. All analyses have a common interface which take in the model, run an analysis, and give back a pre-defined set of artifacts, such as plots of the solution or generated binaries.

Using an Analysis (Dyad Studio) ​

Dyad Studio includes a lower level interface to define and interact with analyses at the Julia level, with more flexibility than what is exposed in the GUI.

Example: TransientAnalysis of a Simple Block ​

Using the Dyad-Level Analysis Interface (Dyad Studio) ​

A TransientAnalysis for the SecondOrderSystemTest component is written in Dyad as:

dyad
analysis SecondOrderSystemTransient
  extends TransientAnalysis(stop=5)
  model = DyadExampleComponents.SecondOrderSystemTest()
end

The Dyad compiler will generate the SecondOrderSystemTransient function that will run the analysis.

@example
using Main.var"##build/.dyad/manual/analysesDyadHygiene#456".transient_man # hide
result = SecondOrderSystemTransient()

We can plot this result, using either Plots.jl or Makie.jl. We'll use Plots here:

@example
using Main.var"##build/.dyad/manual/analysesDyadHygiene#456".transient_man # hide
using Plots
plot(result)

See the plotting guide for more details on how to plot the results of an analysis.

We can also get artifacts from this result, like:

@example
using Main.var"##build/.dyad/manual/analysesDyadHygiene#456".transient_man # hide
using DyadInterface: artifacts
artifacts(result, :SimulationSolutionTable)

For the artifacts allowed for a given analysis, see the pages which define the given analysis.

Defining and Running an Analysis ​

Any analysis is available and meant to run in Julia. For an analysis called MyAnalysis in Dyad, the generated Julia code will be created with the following format:

julia
result = MyAnalysis(; kwargs...)

where the kwargs are keyword arguments corresponding to the arguments of the analysis run definition (i.e. the fields that can be set at the Dyad level). This invocation will be set to automatically have the keyword arguments default to the values defined in the Dyad version, for example for a TransientAnalysis if one had set stop = 10.0, then stop = 10.0 will be the default value in the generated function. These defaults can thus be overruled by declaring the keyword argument, for example MyAnalysis(; stop=20.0) will run a version of the analysis which overrides the stop time to 20.0.

Analysis Result Interface ​

The analysis results can be interacted with in two ways: there are the customizable plot and the artifacts. The most basic usage is to get the artifacts via:

julia
artifacts(result, name::Symbol)

The allowed artifacts can be queried via:

julia
artifacts(results)

which returns a list of all the available artifact names. For more details about all the artifacts,

julia
AnalysisSolutionMetadata(result)

can be used, which also includes descriptions for all the artifacts.

Additionally, some analyses include a customizable visualization:

julia
customizable_visualization(::AbstractAnalysisSolution, ::PlotlyVisualizationSpec)

This will be defined fully in future versions.

Defining Your Own Analysis ​

At the lowest level, analyses are implemented in Julia, see the Custom analysis tutorial for more details on how to write your own.