User API

Problem definition

QuantizedSystemSolver.ODEProblemMethod
ODEProblem(f::Function, u::Vector{Float64}, tspan::Tuple{A,B}, p::Union{Vector{EM}, Tuple{Vararg{EM}}};jac_mode ::Symbol= :symbolic) where{EM,A<:Union{Float64, Int64},B<:Union{Float64, Int64}}

Creates an ODE problem with the given function f, initial conditions u, parameters p, and time span tspan.

Arguments

  • f::Function: The function defining the ODE.
  • u::Vector{Float64}: The initial conditions.
  • p::Vector{Float64}: The parameters.
  • tspan::Tuple{Float64,Float64}: The time span for the ODE.

Returns

  • An ODE problem.
source
QuantizedSystemSolver.ODEProblemMethod
ODEProblem(f::Function, u::Vector{Float64}, tspan::Tuple{A,B};jac_mode ::Symbol= :symbolic) where{A<:Union{Float64, Int64},B<:Union{Float64, Int64}}

Creates an ODE problem with the given function f, initial conditions u, and time span tspan.

Arguments

  • f::Function: The function defining the ODE.
  • u::Vector{Float64}: The initial conditions.
  • tspan::Tuple{Float64,Float64}: The time span for the ODE.

Returns

  • An ODE problem.
source

The solve function:

QuantizedSystemSolver.solveMethod
solve(prob::ODEProblemData{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{SolverType, OrderType};detection::Val{M}=Val(2),saveat::Float64=Inf,abstol::Float64=1e-3,reltol::Float64=1e-3,maxErr::Float64=1.0,maxiters::Int=Int(1e7),verbose=false::Bool) where{F,PRTYPE,T,D,Z,CS,SolverType,OrderType,M}

dispatches on a specific integrator based on the algorithm provided and sends a nonlinear ODE problem to the integrator. With the exception of the argument prob, all other arguments are optional and have default values:

Arguments

  • prob::ODEProblemData{F,PRTYPE,T,D,Z,CS}: The nonlinear ODE problem to solve.
  • al::QSSAlgorithm{SolverType, OrderType}: The QSS algorithm to use for solving the problem.
  • detection::Val{M}: A type parameter indicating which detection mechanism to use.
  • saveat::Float64: The time interval at which to save the solution (default: Inf).
  • abstol::Float64: The absolute tolerance for the solver (default: 1e-4).
  • reltol::Float64: The relative tolerance for the solver (default: 1e-3).
  • maxErr::Float64: The maximum allowable error (default: Inf).
  • maxiters::Int: The maximum number of iterations (default: Int(1e7)).

After the simulation, the solution is returned as a Solution object.

source
QuantizedSystemSolver.solveMethod
solve(prob::ODEProblemData{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{SolverType, OrderType},tspan::Tuple{Float64, Float64};detection::Val{M}=Val(2),saveat::Float64=Inf,abstol::Float64=1e-3,reltol::Float64=1e-3,maxErr::Float64=1.0,maxiters::Int=Int(1e7),verbose=false::Bool) where{F,PRTYPE,T,D,Z,CS,SolverType,OrderType,M}

same as the previous solve method, but with a specified time span. This method is useful when the user wants to specify the time span separately from the problem definition.

source

Algorithms

QuantizedSystemSolver.nmliqss1Method
nmliqss1()

calls the modified imlicit quantized state system solver with order 1. It is efficient when the system contains large entries outside the main diagonal of the Jacobian .

source
QuantizedSystemSolver.nmliqss2Method
nmliqss2()

calls the modified imlicit quantized state system solver with order 2. It is efficient when the system contains large entries outside the main diagonal of the Jacobian .

source

Solution

Query a solution

QuantizedSystemSolver.evaluateSolMethod
evaluateSol(sol::Sol{T,O},index::Int,t::Float64) where {T,O}

Evaluates the solution at a given time t for a specified variable index.

Arguments

  • sol::Sol{T,O}: The solution struct.
  • index::Int: The index of the variable to evaluate. If index is 0, evaluates all variables.
  • t::Float64: The time at which to evaluate the solution.

Returns

  • The value of the specified variable at time t, or a vector of values if index is 0.

Throws

  • An error if the given time t is outside the solution range.
source
QuantizedSystemSolver.solInterpolatedMethod
solInterpolated(sol::Sol{T,O},step::Float64) where {T,O}

Construct a new solution by interpolating the current solution at each step for all variables.

Arguments

  • sol::Sol{T,O}: The solution struct.
  • step::Float64: the step size at which to generate the new solution.

Returns

  • A new solution that contains information at each step size..
source
QuantizedSystemSolver.solInterpolatedMethod
solInterpolated(sol::Sol{T,O},index::Int,step::Float64) where {T,O}

Constructs a new solution by interpolating the current solution at each step for one variable.

Arguments

  • sol::Sol{T,O}: The solution struct.
  • index::Int: the index of the variable to interpolate.
  • step::Float64: the step size at which to generate the new solution.

Returns

  • A new solution that contains the information of one variable at each step size.
source
Base.showMethod
show(io::IO, a::Stats)

Displays the statistics of the simulation.

Arguments

  • io::IO: The IO stream to write to.
  • a::Stats: The Stats struct containing the simulation statistics.

Prints

  • The total simulation steps.
  • The simultaneous steps.
  • The number of events.
  • The number of state steps.
  • The number of input steps.
source
QuantizedSystemSolver.StatsType
Stats

A struct that holds the statistics of a simulation. It has the following fields:

  • totalSteps::Int: The total number of simulation steps.
  • simulStepCount::Int: The number of simultaneous steps.
  • evCount::Int: The number of events.
  • numStateSteps::Vector{Int}: A vector holding the number of steps for each state update.
  • numInputSteps::Vector{Int}: A vector holding the number of steps for each input update.
source

Error with respect to an analytic or reference solution

Finding the error

To find the error, an interpolated solution has to be used as shown in solInterpolated. The reference solution (using saveat for example) and the interpolated solution (passed step to interpolated function) must have the same tspan and the same step size.

QuantizedSystemSolver.getErrorMethod
getError(sol::Sol{T,O},index::Int,f::Function) where{T,O}

calculates the relative error of one variable of the solution with respect to a function of an analytic solution.

\[\begin{equation*} err=\sqrt{\frac{\sum(sol_{index}-f_{index})^2}{\sum(f_{index})^2}} \end{equation*}\]

source
QuantizedSystemSolver.getAverageErrorMethod
getAverageError(sol::Sol{T,O},f::Vector{Function}) where{T,O}

calculates the average relative error of all variables of the solution with respect to a vector of functions of analytic solutions.

\[\begin{align*} & err_{index}=\sqrt{\frac{\sum(sol_{index}-f_{index})^2}{\sum(f_{index})^2}}\ & avgError=\frac{\sum_{index=1}^{T}err_{index}}{T} \end{align*}\]

source
QuantizedSystemSolver.getErrorByRefsMethod
getErrorByRefs(sol::Sol{T,O},index::Int,solRef::Vector{Any}) where{T,O}

calculates the relative error of one variable of the solution with respect to a vector of values received from a reference solution.

\[\begin{equation*} err=\sqrt{\frac{\sum(sol_{index}-solRef_{index})^2}{\sum(solRef_{index})^2}} \end{equation*}\]

source
QuantizedSystemSolver.getAverageErrorByRefsMethod
getAverageErrorByRefs(sol::Sol{T,O},solRef::Vector{Any}) where{T,O}

calculates the average relative error of the solution with respect to a reference solution. The relative error is calculated for each variable, and then it is averaged over all variables.

\[\begin{align*} & err_{index}=\sqrt{\frac{\sum(sol_{index}-solRef_{index})^2}{\sum(solRef_{index})^2}}\ & avgError=\frac{\sum_{index=1}^{T}err_{index}}{T} \end{align*}\]

source

Plot the solution

QuantizedSystemSolver.plot_SolSumMethod
plot_SolSum(sol::Sol{T,O},xvars::Int...;interp=0.0001,note=" "::String,xlims::Tuple{Float64, Float64}=(0.0,0.0),ylims::Tuple{Float64, Float64}=(0.0,0.0),legend::Bool=true) where{T,O}

plots of the sum of the variables xvars.

Arguments

  • sol::Sol{T,O}: The solution struct.
  • xvars::Int...: The indices of the variables to sum. If no indices are provided, all variables are summed.
  • interp::Float64: The interpolation step.
  • note::String: A note to add to the title of the plot.
  • xlims::Tuple{Float64, Float64}: The x-axis limits of the plot.
  • ylims::Tuple{Float64, Float64}: The y-axis limits of the plot.
  • legend::Bool: A boolean indicating whether to display the legend.
source