API

Heta Compiler CLI

HetaImporter.heta_help — Function
heta_help(command::Union{String, Nothing}=nothing)

Displays help for heta-compiler CLI

Arguments:

  • command: command to display. Default is nothing to display general help
HetaImporter.heta_build — Function
heta_build(
  target_dir::AbstractString;
  declaration::String = "platform",
  units_check::Bool = false,
  log_mode::String = "error",
  log_path::String = "build.log",
  log_level::String = "info",
  debug::Bool = false,
  dist_dir::String = "dist",
  meta_dir::String = "meta",
  source::String = "index.heta",
  type::String = "heta",
  export_format::Union{String, Nothing} = nothing,
)

Builds the models from Heta-based platform

See heta compiler docs for details: https://hetalang.github.io/hetacompiler/cli-references.html#running-heta-build-with-options

Arguments:

  • target_dir : path to the directory where Heta platform is located
  • declaration : filepath to the platform declaration file. Default is "platform"
  • units_check : if set to true units will be checked for the consistency
  • log_mode : log mode. Default is "error"
  • log_path : path to the log file. Default is "build.log"
  • log_level : log level to display. Default is "info"
  • debug : turn on debug mode. Default is false
  • dist_dir : directory path, where to write distributives to. Default is "dist"
  • meta_dir : meta directory path. Default is "meta"
  • source : path to the main heta module. Default is "index.heta"
  • type : type of the source file. Default is "heta"
  • export_format : export the model to the specified format: julia,dynms,{format:SBML,version:L3V1}

Julia File Generation

HetaImporter.build_dynms_file — Function
build_dynms_file(heta_dir; build_dir, kwargs...)

Build a Heta platform and write a DynMS JSON file to joinpath(build_dir, DYNMS_MODEL_DIR, DYNMS_MODEL_NAME).

The returned value is the generated DynMS JSON file path.

Arguments:

  • heta_dir : path to a Heta source directory containing a platform declaration file
  • build_dir : directory path where generated files are written. Default is joinpath(heta_dir, "dist")
  • spaceFilter : filter for namespaces in the Heta model. Can be a string, a vector of symbols, or nothing. Default is nothing
  • kwargs : other arguments supported by heta_build
HetaImporter.build_julia_file — Function
build_julia_file(heta_dir; build_dir, ir_format=:julia, kwargs...)

Build a Heta platform and write a Julia source file to joinpath(build_dir, JULIA_MODEL_DIR, JULIA_MODEL_NAME).

heta-compiler writes Julia code directly. The only supported ir_format is :julia. To construct a native HetaODESystem, use import_heta.

The returned value is the generated Julia file path.

Arguments:

  • heta_dir : path to a Heta source directory containing a platform declaration file
  • ir_format : compiler export format. Only :julia is supported.
  • build_dir : directory path where generated files are written. Default is joinpath(heta_dir, "dist")
  • spaceFilter : filter for namespaces in the Heta model. Can be a string, a vector of symbols, or nothing. Default is nothing
  • kwargs : other arguments supported by heta_build

Advanced: DynMS Parsing, Validation, and Conversion

build_dynms_file compiles a Heta project and returns a DynMS file path. parse_dynms reads a DynMS file into an unvalidated dictionary. Pass it to validate_dynms before convert_dynms creates a DynMSModelSet. convert_dynms_model converts one validated model dictionary to a DynMSModel. For a complete file-to-system pipeline, use import_heta or import_dynms.

HetaImporter.parse_dynms — Function
parse_dynms(dynms_filepath::AbstractString)

Parse a DynMS JSON file into a dictionary without validation or conversion. Use import_dynms to construct a HetaODESystem from a file.

HetaImporter.validate_dynms — Function
validate_dynms(dynms_dict::AbstractDict)

Check the supported format version, JSON schema, and semantic consistency of an already-parsed DynMS dictionary. Return nothing on success.

HetaImporter.convert_dynms — Function
convert_dynms(data::AbstractDict; nanmath::Bool=false)

Convert an already-parsed, validated DynMS JSON dictionary into a DynMSModelSet.

Use parse_dynms to read a file and validate_dynms before conversion. The returned specification contains model definitions, Julia expression trees for mathematical expressions, event definitions, and metadata from the DynMS generator.

Set nanmath=true to convert powers, square roots, and logarithms to NaNMath calls. This option applies to every model expression.

HetaImporter.convert_dynms_model — Function
convert_dynms_model(model::AbstractDict; nanmath::Bool=false)

Convert one validated DynMS model dictionary into a DynMSModel.

This is mainly useful when working with a model entry extracted from an already-validated DynMS document. To import a file as a system, use import_dynms; for a Heta project, use import_heta. The nanmath option has the same meaning as in convert_dynms.

Heta Import and ODE Construction

Use import_heta(path; nanmath=true) or import_dynms(path; nanmath=true) to convert powers, square roots, and unary logarithms (log, log10, log2) to NaNMath calls. The default is false. This applies to initialization, equations, assignments/observables, and events.

HetaImporter.import_heta — Function
import_heta(heta_dir, model_id::Symbol=:nameless; write_to_file=false,
            filename=nothing, build_dir=nothing, nanmath=false, kwargs...)

Compile a Heta project to DynMS and delegate to import_dynms to construct a native HetaODESystem. Remaining keyword arguments are forwarded to build_dynms_file. The selected model defaults to :nameless and must exist.

By default, compiler output is stored in a temporary directory that is removed after import, including on failure. Set build_dir to retain compiler output in a specific directory.

Set nanmath=true to use NaNMath for powers, square roots, and logarithms throughout the converted model. See import_dynms.

HetaImporter.import_heta_all — Function
import_heta_all(heta_dir; write_to_file=false, output_dir=".", nanmath=false, kwargs...)

Compile a Heta project and return every model as an OrderedDict{Symbol,<:HetaODESystem} keyed by model ID. Remaining keyword arguments are forwarded to build_dynms_file.

When write_to_file=true, readable generated code is written to <output_dir>/<model_id>_ode.jl for each system. The nanmath option applies to every model; see import_dynms.

HetaImporter.import_dynms — Function
import_dynms(dynms_filepath, model_id::Symbol=:nameless; write_to_file=false,
             filename=nothing, nanmath=false)

Parse and validate a DynMS JSON file, convert it to a model set, and build the selected model as a native HetaODESystem. The selected model defaults to :nameless and must exist. When write_to_file=true, generated Julia source is also written to filename.

With nanmath=true, powers, square roots, and log, log10, and log2 calls use NaNMath in all model expressions, including initialization and events. The converted expressions are also visible through the inspection functions.

HetaImporter.HetaODESystem — Type
HetaODESystem

Native Julia representation of a parsed Heta ODE model. dynms retains the semantic model for inspection and generated_code contains the fixed, uncompiled Julia functions generated once by build_ode_system. Functions are generated for all events, including those inactive by default; event activation is resolved separately for each ODEProblem. scenarios contains the simulation regimens referencing this model, keyed by ID.

parameter_index indexes the complete flattened parameter container (tunables, derived, then discretes). discrete_index indexes only the discrete portion and is also used as its parameter-timeseries index.

HetaImporter.HetaParameters — Type
HetaParameters(tunable, nderived, ndiscrete, initialize_parameters!)

Runtime parameter storage used by the native Julia backend. tunable contains the flat values exposed to optimizers, derived contains values recalculated from tunables at the start of a solve, and discrete contains values that callbacks may mutate during integration.

initialize_parameters!(derived, discrete, tunable) is generated with the model. It is called by the constructor and whenever the Tunable portion is replaced. Replacing only the Discrete portion restores values saved during a simulation without reinitializing them.

HetaImporter.build_ode_system — Function
build_ode_system(model; write_to_file=false, filename=nothing)
build_ode_system(model_set; model_id, kwargs...)

Lower a parsed DynMS model to a native HetaODESystem.

When write_to_file=true, readable Julia source for the resulting system is also written to filename.

HetaImporter.write_generated_code — Function
write_generated_code(system, filename)

Write the fixed native Julia functions stored in system.generated_code to a readable source file. No code is regenerated.

HetaImporter.observed — Function

Return the assignment-rule expressions available as observed variables.

HetaImporter.events — Function

Return time, crossing (continuous), and conditional (discrete) events. Non-time events carry a stop_simulation flag.