User API

Problem definition

QuantizedSystemSolver.ODEProblemMethod
ODEProblem(f::Function, u::Vector{Float64}, tspan::Tuple{Float64,Float64}, p::Union{Vector{EM}, Tuple{Vararg{EM}}}) where{EM}

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{Float64,Float64})

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::NLODEProblem{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{SolverType, OrderType};detection::Val{M}=Val(3),saveat=Inf::Float64,abstol=1e-3::Float64,reltol=1e-2::Float64,maxErr=Inf::Float64,maxiters=Int(1e7)::Int) where{F,PRTYPE,T,D,Z,CS,SolverType,OrderType,M}

dispatches on a specific integrator based on the algorithm provided and send a nonlinear ODE problem to the integrator.

Arguments

  • prob::NLODEProblem{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-3).
  • reltol::Float64: The relative tolerance for the solver (default: 1e-2).
  • maxErr::Float64: The maximum allowable error (default: Inf).
  • maxiters::Int: The maximum number of iterations (default: Int(1e7)).
source
QuantizedSystemSolver.solveMethod
solve(prob::NLODEProblem{F,PRTYPE,T,D,Z,CS},al::QSSAlgorithm{SolverType, OrderType},tspan::Tuple{Float64, Float64};detection::Val{M}=Val(3),saveat=Inf::Float64,abstol=1e-3::Float64,reltol=1e-2::Float64,maxErr=Inf::Float64,maxiters=Int(1e7)::Int) where{F,PRTYPE,T,D,Z,CS,SolverType,OrderType,M}

dispatches on a specific integrator based on the algorithm provided and send a nonlinear ODE problem to the integrator.

With the exception of the argument prob and tspan, all other arguments are optional and have default values:

  • The algorithm defaults to nmliqss2, and it is specified by the QSSAlgorithm type, which is a composite type that has a name and an order. It can be extended independently of the solver.
  • The detection argument defaults to 1.
  • The saveat argument defaults to Inf. It specifies the time step at which the integrator will save the solution (not implemented).
  • The abstol argument defaults to 1e-3. It specifies the absolute tolerance of the integrator.
  • The reltol argument defaults to 1e-2. It specifies the relative tolerance of the integrator.
  • The maxErr argument defaults to Inf. It specifies the maximum error allowed by the integrator. This is used as an upper bound for the quantum when a variable goes large.
  • The maxiters argument defaults to 1e7. It specifies the maximum number of steps allowed by the integrator. If the user wants to extend the limit on the maximum number of steps, this argument can be used.

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

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.
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.
  • numSteps::Vector{Int}: A vector holding the number of steps for each variable.
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

RecipesBase.plotMethod
plot(sol::Sol{T,O};idxs=Int[]::Vector{Int},note=" "::String,xlims=(0.0,0.0)::Tuple{Float64, Float64},ylims=(0.0,0.0)::Tuple{Float64, Float64},legend=:true::Bool,marker=:circle::Symbol,title="") where{T,O}

generates a plot of the solution of the system (returned as a plot object). With the exception of the solution object, all arguments are optional.

arguments:

  • sol::Sol{T,O}: The solution struct.
  • xvars::Int...: The indices of the variables to plot. If no indices are provided, all variables are plotted.
  • idxs::::Vector{Float64}: The indices of the variables to plot. If no indices are provided, all variables are plotted.
  • 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.
  • marker::Symbol: The marker to use for the plot.
  • title::String: The title of the plot.
source
QuantizedSystemSolver.plot_SolMethod
plot_Sol(sol::Sol{T,O},xvars::Int...;note=" "::String,xlims=(0.0,0.0)::Tuple{Float64, Float64},ylims=(0.0,0.0)::Tuple{Float64, Float64},legend=:true::Bool,marker=:circle::Symbol,title="") where{T,O}

generates a plot of the solution of the system (returned as a plot object). With the exception of the solution object, all arguments are optional.

arguments:

  • sol::Sol{T,O}: The solution struct.
  • xvars::Int...: The indices of the variables to plot. If no indices are provided, all variables are plotted.
  • 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.
  • marker::Symbol: The marker to use for the plot.
  • title::String: The title of the plot.
source
QuantizedSystemSolver.plot_SolSumMethod
plot_SolSum(sol::Sol{T,O},xvars::Int...;interp=0.0001,note=" "::String,xlims=(0.0,0.0)::Tuple{Float64, Float64},ylims=(0.0,0.0)::Tuple{Float64, Float64},legend=:true::Bool) 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