SciGenML

Documentation for SciGenML.

SciGenML.Models.ConditionalFlowMatchingType
ConditionalFlowMatching

A conditional flow matching generative model.

The conditional flow matching generative model is a generative model that uses a flow matching approach to generate data.

It is a special case of the conditional stochastic interpolant generative model where there is no noise in the interpolant.

source
SciGenML.Models.DeterministicInterpolantCoefsType
DeterministicInterpolantCoefs

A struct that contains the alpha and beta function coefficients and their derivatives.

The interpolant is defined as:
x(t) = α(t) * x0 + β(t) * x1

The derivatives are:
dx/dt = α'(t) * x0 + β'(t) * x1
source
SciGenML.Models.FlowMatchingType
FlowMatching

A flow matching generative model.

The flow matching generative model is a generative model that uses a flow matching approach to generate data.

It is a special case of the stochastic interpolant generative model where there is no noise in the interpolant.

source
SciGenML.Models.ScoreBasedDiffusionModelType
ScoreBasedDiffusionModel

A score-based diffusion model generative model.

The score-based diffusion model generative model is a generative model that uses a score-based diffusion model approach to generate data.

It is a special case of the stochastic interpolant generative model where there is no noise in the interpolant.

source
SciGenML.Models.StochasticInterpolantCoefsType
StochasticInterpolantCoefs

A struct that contains the alpha and beta function coefficients and their derivatives.

The interpolant is defined as:
x(t) = α(t) * x0 + β(t) * x1 + γ(t) * Z

The derivatives are:
dx/dt = α'(t) * x0 + β'(t) * x1 + γ'(t) * Z
source
SciGenML.Models.compute_interpolantMethod
compute_interpolant(x0, x1, z, t, interpolant_coefs::StochasticInterpolantCoefs)

Computes the stochastic interpolant at a given time.

Args:
    x0: The starting point.
    x1: The ending point.
    z: The noise.
    t: The time.
    interpolant_coefs: The interpolant coefficients.
source
SciGenML.Models.compute_interpolantMethod
Computes the deterministic interpolant at a given time.

Args:
    x0: The starting point.
    x1: The ending point.
    t: The time.
    interpolant_coefs: The interpolant coefficients.
source
SciGenML.Models.compute_interpolant_diffMethod
compute_interpolant_diff

Computes the derivative of the interpolant at a given time.

Args:
    x0: The starting point.
    x1: The ending point.
    interpolant_coefs: The interpolant coefficients.
    t: The time.
source
SciGenML.Models.diffusion_interpolant_coefsFunction
diffusion_interpolant_coefs(trait::Models.Deterministic)

Returns the quadratic interpolant.

The quadratic interpolant is defined as:
α(t) = exp(-multiplier * t)
β(t) = sqrt(1 - exp(-2 * multiplier * t))

The derivatives are:
α'(t) = -multiplier * exp(-multiplier * t)
β'(t) = multiplier * exp(-multiplier * t) / sqrt(1 - exp(-2 * multiplier * t))
source
SciGenML.Models.drift_termMethod
drift_term(
    ::Models.Deterministic,
    model::Models.ConditionalFlowMatching,
)

Get the drift term for the conditional flow matching generative model.
source
SciGenML.Models.drift_termMethod
drift_term(
    ::Models.Stochastic,
    model::StochasticInterpolant, 
    diffusion_fn, 
)

Compute the drift term for a stochsatic interpolant.
source
SciGenML.Models.drift_termMethod
drift_term(
    ::Models.Stochastic,
    model::StochasticInterpolant, 
    diffusion_fn, 
)

Compute the drift term for a stochsatic interpolant.
source
SciGenML.Models.drift_termMethod
drift_term(
    ::Models.Stochastic,
    model::StochasticInterpolant, 
    diffusion_fn, 
    x, 
    ps, 
    st
)

Compute the drift term for a stochastic interpolant.
source
SciGenML.Models.linear_interpolant_coefsFunction
linear_interpolant_coefs(trait::Models.Deterministic)

Returns the linear interpolant.

The linear interpolant is defined as:
α(t) = 1 - t
β(t) = t
γ(t) = 1 - t, if trait == Models.Stochastic

The derivatives are:
α'(t) = -1
β'(t) = 1
γ'(t) = -1, if trait == Models.Stochastic
source
SciGenML.Models.quadratic_interpolant_coefsFunction
quadratic_interpolant_coefs(trait::Models.Deterministic)

Returns the quadratic interpolant.

The quadratic interpolant is defined as:
α(t) = 1 - t
β(t) = t^2
γ(t) = 1 - t, if trait == Models.Stochastic

The derivatives are:
α'(t) = -1
β'(t) = 2t
γ'(t) = -1, if trait == Models.Stochastic
source
SciGenML.Architectures.DenseNeuralNetworkMethod
DenseNN(
    in_features::Tuple,
    out_features::Int, 
    hidden_features::Vector{Int};
    activation_function = DEFAULT_ACTIVATION_FUNCTION,
    dropout = DEFAULT_DROPOUT
)

in_features: A tuple of the number of input features
out_features: The number of output features.
hidden_features: The number of hidden features.
activation_function: The activation function.

A dense neural network with `in_features` input features, 
`out_features` output features, and `hidden_features` hidden features.
The input is a tuple that are concatenated to form a single input.
source
SciGenML.Architectures.UNetMethod
UNet(
    in_channels::Int,
    out_channels::Int,
    hidden_channels,
    time_embedding_dim::Int
    padding::String,
)

A UNet model.

# Arguments
- `in_channels::Int`: The number of input channels.
- `out_channels::Int`: The number of output channels.
- `hidden_channels::List{Int}`: The number of hidden channels in each layer.
- `time_embedding_dim::Int`: The dimension of the time embedding.
- `scalar_in_conditioning_dim::Int`: The dimension of the scalar input conditioning.
- `scalar_hidden_conditioning_dim::Int`: The dimension of the hidden scalar conditioning.
- `padding::String`: The padding type.
source
SciGenML.Architectures.UNetMethod
UNet(
    in_channels::Int,
    out_channels::Int,
    hidden_channels,
    time_embedding_dim::Int
    padding::String,
)

A UNet model.

# Arguments
- `in_channels::Int`: The number of input channels.
- `out_channels::Int`: The number of output channels.
- `hidden_channels::List{Int}`: The number of hidden channels in each layer.
- `time_embedding_dim::Int`: The dimension of the time embedding.
- `padding::String`: The padding type.
- `field_in_conditioning_dim::Int`: The dimension of the field input conditioning.
- `field_hidden_conditioning_dim::Int`: The dimension of the hidden field conditioning.
- `field_conditioning_combination::String`: The combination method for the field conditioning.
source
SciGenML.Architectures.UNetMethod
UNet(
    in_channels::Int,
    out_channels::Int,
    hidden_channels,
    time_embedding_dim::Int
    padding::String,
)

A UNet model.

# Arguments
- `in_channels::Int`: The number of input channels.
- `out_channels::Int`: The number of output channels.
- `hidden_channels::List{Int}`: The number of hidden channels in each layer.
- `time_embedding_dim::Int`: The dimension of the time embedding.
- `padding::String`: The padding type.
source
SciGenML.Architectures.UNetMethod
UNet(config::Config.UNetHyperparameters)

A UNet model.

# Arguments
- `config::Config.UNetHyperparameters`: The configuration for the UNet model.
source
SciGenML.Architectures.get_modelMethod
get_model(
    in_features,
    out_features,
    hidden_features,
    activation_function = DEFAULT_ACTIVATION_FUNCTION,
    dropout = DEFAULT_DROPOUT
)

in_features: The number of input features.
out_features: The number of output features.
hidden_features: The number of hidden features.
activation_function: The activation function.
dropout: The dropout rate.

Returns a model that can be used to predict the output from the input.
source
SciGenML.Layers.conv_next_blockMethod
conv_next_block(
    in_channels::Int, 
    out_channels::Int,
    multiplier::Int = 1,
    pars_embed_dim::Int = 1,
    imsize::Tuple{Int, Int} = (64, 128)
)

Create a conv next block with the given number of input and output channels. The block consists of two convolutional layers with kernel size kernel_size. The first layer has the same number of input and output channels, while the second layer has the same number of output channels as the block. The block also includes batch normalization and a skip connection.

https://arxiv.org/abs/2201.03545

Based on https://github.com/tum-pbs/autoreg-pde-diffusion/blob/b9b33913b99ede88d9452c5ab470c5d7f5da5c56/src/turbpred/modeldiffusionblocks.py#L60

source
SciGenML.Layers.conv_next_block_no_conditioningMethod
conv_next_block_no_conditioning(
    in_channels::Int, 
    out_channels::Int,
    multiplier::Int = 1,
    imsize::Tuple{Int, Int} = (64, 128)
)

Create a conv next block with the given number of input and output channels. The block consists of two convolutional layers with kernel size kernel_size. The first layer has the same number of input and output channels, while the second layer has the same number of output channels as the block. The block also includes batch normalization and a skip connection.

https://arxiv.org/abs/2201.03545

Based on https://github.com/tum-pbs/autoreg-pde-diffusion/blob/b9b33913b99ede88d9452c5ab470c5d7f5da5c56/src/turbpred/modeldiffusionblocks.py#L60

source
SciGenML.Layers.multiple_conv_next_blocksMethod
multiple_conv_next_blocks(
    in_channels::Int, 
    out_channels::Int,
    multiplier::Int = 1,
    conditioning_dim::Int = 1,
    imsize::Tuple{Int, Int} = (64, 128)
)

Create a chain of two conv next blocks with the given number of input and output channels. The first block has the same number of input and output

source
SciGenML.Layers.multiple_conv_next_blocks_no_conditioningMethod
multiple_conv_next_blocks_no_conditioning(
    in_channels::Int, 
    out_channels::Int,
    multiplier::Int = 1,
    padding="constant"
)

Create a chain of two conv next blocks with the given number of input and output channels. The first block has the same number of input and output

source
SciGenML.Layers.sinusoidal_embeddingFunction
sinusoidal_embedding(
    x::AbstractArray{AbstractFloat, 4},
    min_freq::AbstractFloat,
    max_freq::AbstractFloat,
    embedding_dims::Int
)

Embed the noise variances to a sinusoidal embedding with the given frequency range and embedding dimensions.

Based on https://yng87.page/en/blog/2022/lux-ddim/.

source
SciGenML.Data.load_kolmogorov_dataFunction
load_kolmogorov_data(;
    num_trajectories = 5,
    num_skip_steps = 5,
    num_steps = 100,
    start_step = 500
)
Load the Kolmogorov data.

Outputs a named tuple with the following fields:
- `base`: The base data. [H, W, C, (T-1)*N]
- `target`: The target data. [H, W, C, (T-1)*N]
- `field_conditioning`: The field conditioning data. [H, W, C, (T-1)*N]
source
SciGenML.Data.load_super_res_kolmogorov_dataFunction
load_super_res_kolmogorov_data(;
    num_trajectories = 5,
    num_skip_steps = 5,
    num_steps = 100,
    start_step = 500
)
Load the super-resolution Kolmogorov data.

Outputs a named tuple with the following fields:
- `base`: The base data. [H, W, C, (T-1)*N]
- `target`: The target data. [H, W, C, (T-1)*N]
- `field_conditioning`: The field conditioning data. [H, W, C, (T-1)*N]
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Deterministic,
    model::Models.FlowMatching,
    num_samples::Int,
    num_steps::Int,
    rng::Random.AbstractRNG = Random.default_rng()
)

Sample from a stochastic interpolant generative model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Deterministic,
    model::Models.FlowMatching,
    num_samples::Int,
    num_steps::Int,
    rng::Random.AbstractRNG = Random.default_rng()
)

Sample from a stochastic interpolant generative model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Deterministic,
    model::Models.ScoreBasedDiffusionModel,
    num_samples::Int,
    num_steps::Int,
    rng::Random.AbstractRNG = Random.default_rng()
)

Sample from a denoising diffusion model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Deterministic,
    model::Models.StochasticInterpolantGenerativeModel,
    num_samples::Int,
    num_steps::Int,
    rng::Random.AbstractRNG = Random.default_rng()
)

Sample from a stochastic interpolant generative model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Stochastic,
    model::Models.FollmerStochasticInterpolant,
    scalar_conditioning,
    num_steps::Int,
    num_samples::Int,
    prior_samples = nothing,
    diffusion_fn = nothing,
    rng::Random.AbstractRNG = Random.default_rng(),
    verbose::Bool = true,
    stepper = TimeIntegrators.heun_step
)

Sample from a stochastic interpolant generative model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Stochastic,
    model::Models.ScoreBasedDiffusionModel,
    num_samples::Int,
    num_steps::Int,
    rng::Random.AbstractRNG = Random.default_rng()
)

Sample from a denoising diffusion model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Stochastic,
    model::Models.ScoreBasedDiffusionModel,
    num_samples::Int,
    num_steps::Int,
    num_samples::Int,
    prior_samples,
    diffusion_fn,
    rng::Random.AbstractRNG = Random.default_rng(),
    verbose::Bool = true,
    stepper = TimeIntegrators.heun_step
)

Sample from a denoising diffusion model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Stochastic,
    model::Models.StochasticInterpolant,
    scalar_conditioning,
    num_steps::Int,
    num_samples::Int,
    prior_samples = nothing,
    diffusion_fn = nothing,
    rng::Random.AbstractRNG = Random.default_rng(),
    verbose::Bool = true,
    stepper = TimeIntegrators.heun_step
)

Sample from a stochastic interpolant generative model using the forward Euler method.
source
SciGenML.Sampling.sampleMethod
sample(
    ::Models.Stochastic,
    model::Models.StochasticInterpolantGenerativeModel,
    num_samples::Int,
    num_steps::Int,
    rng::Random.AbstractRNG = Random.default_rng()
)

Sample from a stochastic interpolant generative model using the forward Euler method.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Deterministic,
    model::Models.ConditionalFlowMatching,
    base_samples,
    target_samples,
    scalar_conditioning_samples,
    train_state,
    rng
)

Train a stochastic interpolant generative model for one step.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Deterministic,
    model::Models.FlowMatching,
    base_samples,
    target_samples,
    train_state,
    rng
)

Train a flow matching generative model for one step.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Deterministic,
    model::Models.FlowMatching,
    base_samples,
    target_samples,
    field_conditioning,
    train_state,
    rng
)

Train a flow matching generative model for one step.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Deterministic,
    model::Models.StochasticInterpolant,
    base_samples,
    target_samples,
    train_state,
    rng
)

Train a stochastic interpolant generative model for one step.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Deterministic,
    model::Models.ScoreBasedDiffusionModel,
    base_samples,
    target_samples,
    train_state,
    rng
)

Train a score-based diffusion generative model for one step via flow matching.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Deterministic,
    model::Models.ScoreBasedDiffusionModel,
    base_samples,
    target_samples,
    conditioning,
    train_state,
    rng
)

Train a score-based diffusion generative model for one step via flow matching.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Stochastic,
    model::Models.FollmerStochasticInterpolant,
    base_samples,
    target_samples,
    field_conditioning,
    train_state,
    rng
)

Train a stochastic interpolant generative model for one step.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Stochastic,
    model::Models.StochasticInterpolant,
    base_samples,
    target_samples,
    train_state,
    rng
)

Train a stochastic interpolant generative model for one step.
source
SciGenML.Training._train_stepMethod
_train_step(
    ::Models.Stochastic,
    model::Models.StochasticInterpolant,
    base_samples,
    target_samples,
    scalar_conditioning,
    train_state,
    rng
)

Train a stochastic interpolant generative model for one step.
source
SciGenML.Training.get_dataloaderFunction
get_dataloader(
    base,
    target,
    scalar_conditioning,
    batch_size::Int,
    match_base_and_target::Bool=false
)

Get a dataloader from a base, target, and conditioning.
source
SciGenML.Training.trainFunction
train(
    ::Models.Deterministic,
    model::Models.ScoreBasedDiffusionModel,
    data,
    config,
    rng = Random.default_rng();
    verbose = true,
    checkpoint = nothing
)

Train a score-based diffusion generative model vis flow matching.
source
SciGenML.Training.trainFunction
train(
    ::Models.Deterministic,
    model::Models.FlowMatching,
    data,
    config,
    rng = Random.default_rng();
    verbose = true,
    checkpoint = nothing
)

Train a stochastic interpolant generative model.
source
SciGenML.Training.trainFunction
train(
    ::Models.Stochastic,
    model::Models.FollmerStochasticInterpolant,
    data,
    config,
    rng = Random.default_rng();
    verbose = true,
    checkpoint = nothing
)

Train a Follmer stochastic interpolant generative model.
source
SciGenML.Training.trainFunction
train(
    ::Models.Stochastic,
    model::Models.StochasticInterpolantGenerativeModel,
    data,
    config,
    rng = Random.default_rng();
    verbose = true
)

Train a stochastic interpolant generative model.
source
SciGenML.Training.trainFunction
train(
    ::Models.Deterministic,
    model::Models.StochasticInterpolantGenerativeModel,
    data,
    config,
    rng = Random.default_rng();
    verbose = true,
    checkpoint = nothing
)

Train a stochastic interpolant generative model.
source
SciGenML.Training.trainFunction
train(
    ::Models.Deterministic,
    model::Models.ConditionalFlowMatching,
    data,
    config,
    rng = Random.default_rng();
    verbose = true
)

Train a stochastic interpolant generative model.
source