% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rxMemoryEstimate.R
\name{rxMemoryEstimate}
\alias{rxMemoryEstimate}
\title{Estimate memory required by rxSolve() for a given dataset and model}
\usage{
rxMemoryEstimate(
  dat,
  model = NULL,
  control = NULL,
  neq = 1L,
  stateSize = neq,
  nlhs = 0L,
  npars = neq,
  neta = 0L,
  neps = 0L,
  ncov = 0L,
  nsim = 1L,
  cores = 1L,
  nMtime = 0L,
  extraCmt = 0L,
  linB = FALSE,
  nLlik = 0L,
  nIndSim = NULL,
  numLinSens = 0L,
  numLin = 0L
)
}
\arguments{
\item{dat}{A \code{\link{rxMemSummary}}, a data.frame with
\code{nobs}/\code{ndoses} columns, or a full event-table
data.frame with an \code{evid} column. This can also be a
serialized solve state file path, a solve state bundle list
containing an \code{events} element, or an \code{rxSolve}
object (using its stored solve events).}

\item{model}{Optional rxode2 model object.  When supplied,
\code{neq}, \code{nlhs}, \code{npars}, \code{extraCmt},
\code{linB}, \code{nMtime}, \code{nLlik}, and \code{nIndSim} are
extracted automatically.}

\item{control}{Optional \code{\link{rxControl}} object.  When
supplied, \code{cores}, \code{nsim}, \code{neta} (from
\code{omega}), \code{neps} (from \code{sigma}), and \code{nLlik}
(adjusted by \code{nLlikAlloc}) are overridden automatically.}

\item{neq}{Number of ODE states.}

\item{stateSize}{Effective \code{state.size()} seen by the solver.
Equals \code{neq} for pure ODE models; may differ for linCmt-only
models.  Defaults to \code{neq}.}

\item{nlhs}{Number of LHS (calculated) output variables.}

\item{npars}{Number of model parameters (drives \code{gpars} size).}

\item{neta}{Number of random effects (etas).}

\item{neps}{Number of residual-error levels (epsilons).}

\item{ncov}{Number of time-varying covariates.}

\item{nsim}{Number of simulations.}

\item{cores}{Number of parallel OMP threads.}

\item{nMtime}{Number of model measurement times.}

\item{extraCmt}{Extra compartments (0, 1 = depot, 2 =
depot+central).}

\item{linB}{\code{TRUE}/\code{1} if using a linear-compartment
model.}

\item{nLlik}{Number of log-likelihood terms (FOCEi use).}

\item{nIndSim}{Per-individual simulation count.  Defaults to
\code{neta + neps} when not supplied explicitly.}

\item{numLinSens}{Number of linear sensitivity parameters (FOCEi +
linCmt).}

\item{numLin}{Number of linear compartment terms (FOCEi + linCmt).}
}
\value{
A named list of class \code{"rxMemoryEstimate"} whose
elements are raw byte counts plus \code{outputData},
\code{ramBytes}, \code{freeRamBytes}, \code{total},
\code{sizeofInd}, and \code{rxLlikSaveSize}.
}
\description{
Accepts either a pre-summarized per-ID table (an \code{\link{rxMemSummary}}
or any data.frame with \code{nobs} and \code{ndoses} columns) or a full
event-table data.frame with an \code{evid} column.  Model dimensions can
be supplied via a compiled rxode2 model object or overridden individually.
}
\details{
The byte counts are computed by \code{rxMemoryComponents_()} which calls
the same \code{rxFillMemLayout()} used by the real allocator, so any
change to the allocation formulas propagates here automatically.
}
\examples{

\donttest{

mod <- rxode2::rxode2({
  d/dt(depot)  <- -ka * depot
  d/dt(center) <- ka * depot - cl / v * center
  cp           <- center / v
})

ev <- rxode2::et(amt = 100, ii = 24, until = 168) |>
  rxode2::et(seq(0, 168, by = 1))

# Basic estimate from event table and model
rxMemoryEstimate(as.data.frame(ev), model = mod)

# With rxControl: population simulation with omega and 4 cores
ctrl <- rxode2::rxControl(
  cores = 4L,
  omega = lotri::lotri(eta.ka ~ 0.09, eta.cl ~ 0.04)
)
rxMemoryEstimate(as.data.frame(ev), model = mod, control = ctrl)

}
}
