---
url: /dyad/stable/manual/analyses.md
description: Learn about how to use and make your own analyses for your Dyad models.
---

# Analyses {#Analyses}

Download as a Dyad projecttransient_man.zipOpen in Dyad Studio›

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:

* [Simulate the model over a given time span](../analyses/transient.md)

* [Auto-tune a PID](../analyses/pid_autotuning.md)

* [Build an FMU](../analyses/fmugeneration.md)

* [Calibrate the model to data](../analyses/fmugeneration.md)

* Run a parameter sweep

and much more. All analyses have a [common interface](/manual/analyses#analysis-result-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) {#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 {#Example:-TransientAnalysis-of-a-Simple-Block}

## Using the Dyad-Level Analysis Interface (Dyad Studio) {#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.

```julia
result = SecondOrderSystemTransient()
```

```ansi
Transient Analysis Solution for DyadExampleComponents.SecondOrderSystemTest
with 2 differential equations and 0 algebraic equations

retcode: Success
Interpolation: 3rd order Hermite
t: 182-element Vector{Float64}: [0.0, 9.999999999999999e-5 … 4.994457445466363, 5.0]
u: 182-element Vector{Vector{Float64}}:
 [0.0, 0.0]
 [5.23599e-12, 1.5708e-7]
 [2.72152e-7, 0.000218623]
 [1.45131e-5, 0.00306922]
 [9.42493e-5, 0.0104176]
 [0.000319947, 0.0224379]
 [0.000791179, 0.0378969]
 [0.00157842, 0.0530896]
 [0.00269796, 0.0627454]
 [0.00408712, 0.06044]
 ⋮
 [0.152786, 0.000750188]
 [0.152843, 0.00732457]
 [0.153429, 0.0337495]
 [0.154631, 0.056428]
 [0.156366, 0.0630568]
 [0.158224, 0.0413059]
 [0.158963, 0.0163164]
 [0.159153, 0.000481222]
 [0.159154, -1.0682e-7]
```

We can plot this result, using either [Plots.jl](https://docs.juliaplots.org/stable/) or [Makie.jl](https://docs.makie.org/stable/).  We'll use Plots here:

```julia
using Plots
plot(result)
```

![](qkihjyp.svg)

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

We can also get artifacts from this result, like:

```julia
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 {#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 {#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 {#Defining-Your-Own-Analysis}

At the lowest level, analyses are implemented in Julia, see the [Custom analysis tutorial](/manual/advanced/custom_analysis#advanced-custom-analysis) for more details on how to write your own.
