LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
line::util Namespace Reference

Namespaces

namespace  timeout_detail

Classes

class  LineConsole
struct  ProcResult
 Outcome of a captured command. More...
class  Sha256
 Incremental SHA-256. More...
class  TempDir
class  TimeoutScope
 The RAII frame timeout_arm returns. More...

Enumerations

enum class  VerboseLevel { SILENT = 0 , STD = 1 , DEBUG = 2 }
 Session verbosity, the twin of MATLAB's VerboseLevel, jline.VerboseLevel and python's line_solver.constants.VerboseLevel. More...

Functions

double timeout_remaining ()
 Seconds left on the innermost armed budget; +Inf when none is armed.
bool timeout_armed ()
 Whether any budget is armed on this thread.
bool timeout_exceeded ()
 The checkpoint: true when the innermost budget has run out, marking it tripped.
bool timeout_tripped ()
 Whether the innermost budget was tripped by a checkpoint or by timeout_trip.
void timeout_trip ()
 Mark the innermost budget tripped without reading the clock: for an external engine that REPORTS it stopped on the budget (LDES stoppingReason == "max_time", a JSIM run given -maxtime).
void timeout_check (const char *where)
 The raising checkpoint, for a computation with no valid partial result: throws LINE:numerical:Timeout naming where when the budget has run out.
int timeout_kill_seconds (double grace=30.0)
 The hard kill bound of a child process under the armed budget: the remaining seconds plus grace, rounded up, as MATLAB's lineTimeoutKillPrefix builds timeout -k 5 ceil(remaining+30).
int timeout_kill_bound (int explicit_seconds, double grace=30.0)
 The kill bound of a child that also has a bound of its OWN (explicit_seconds, not positive = none): the tighter of the two, 0 when neither is set.
void timeout_raise_if_killed_on_budget (const std::string &who)
 A child process was killed on its bound: raise LINE:numerical:Timeout when the armed budget is what ran out (a killed child wrote no result, so there is no partial one), and return otherwise so the caller reports its own bound.
TimeoutScope timeout_arm (double budget)
 Arm budget seconds for the scope's lifetime, capped by the outer frame's remaining time.
void timeout_warn (const std::string &solver, double budget)
 The one warning a solve that stopped on its budget prints, MATLAB's flagTimeout text, on stderr as every other [LINE] Warning here.
std::string method_type (const std::string &solvername, const std::string &method)
 Banner classification of a solution method.
std::string sha256_hex (const std::string &data)
 The digest of a byte string, as 64 lowercase hex characters.
std::string sha256_file_hex (const std::string &path)
 The digest of a file's contents, streamed.
ProcResult capture (const std::vector< std::string > &argv, int timeoutSeconds, bool mergeStderr=false)
 Runs a command, capturing stdout and discarding stderr.
int run_inherit (const std::vector< std::string > &argv)
 Runs a command with the parent's stdout and stderr, e.g.
std::string trim (const std::string &s)
 Trims ASCII whitespace from both ends, as Java's String.trim() does.
std::string make_temp_dir (const std::string &prefix, bool mountable=false)
 Create a private scratch directory named after its caller.

Enumeration Type Documentation

◆ VerboseLevel

enum class line::util::VerboseLevel
strong

Session verbosity, the twin of MATLAB's VerboseLevel, jline.VerboseLevel and python's line_solver.constants.VerboseLevel.

The ordering matters and matches theirs: SILENT < STD < DEBUG.

This port had none until the console became DEBUG. A per-run bool verbose still travels with each solver's options and still means STD-or-SILENT; DEBUG is a SESSION level, because the console must also narrate the model compile, which happens before any solver options exist.

Enumerator
SILENT 
STD 
DEBUG 

Definition at line 57 of file line_console.h.

Function Documentation

◆ capture()

ProcResult line::util::capture ( const std::vector< std::string > & argv,
int timeoutSeconds,
bool mergeStderr = false )
inline

Runs a command, capturing stdout and discarding stderr.

mergeStderr sends the child's stderr down the SAME pipe instead, which is what MATLAB's [status, cmdout] = system(cmd) does and what a wrapper needs on the failure path: an external engine reports why it refused on stderr, and dropping it leaves the wrapper reporting an exit code and nothing else.

Parameters
argvthe command and its arguments, argv[0] resolved on PATH
timeoutSecondsdeadline; not positive waits indefinitely
mergeStderrcapture stderr too, interleaved with stdout
Returns
the exit code, the captured output and whether the deadline expired

Definition at line 82 of file subprocess.h.

References capture(), line::util::ProcResult::exitCode, line::util::ProcResult::out, and line::util::ProcResult::timedOut.

Referenced by capture(), line::io::tikz_detail::compile_pdf(), line::io::docker_daemon_available(), line::io::docker_has_local_image(), line::io::wfcommons_detail::fetch_https(), line::jmt::jmt_run(), line::jmt::jmt_run_docker(), line::jmt::jmt_version(), line::lqns::qnsolver_is_available(), line::ldes::solver_ldes_text(), line::sym::sym_stop_container(), line::io::tikz_export_png(), and line::io::tikz_pdflatex_available().

◆ make_temp_dir()

std::string line::util::make_temp_dir ( const std::string & prefix,
bool mountable = false )
inline

Create a private scratch directory named after its caller.

LINE_WORKSPACE_ROOT RELOCATES EVERY STAGED MODEL, exactly as it does in lineTempName.m, SysUtils.lineTempName and the native-Python wrappers. run-tests.sh sets it when it wraps lqns, lqsim or qnsolver in a container: the shim bind-mounts that root and nothing else, so a model left under TMPDIR is invisible to the binary, which then writes no result and is reported as having rejected the model. No wrapper here needs to know a container is involved.

mountable is the second argument of lineTempName: a snap-confined Docker daemon bind-mounts neither the system temp dir nor a dot-directory, so a caller that hands the directory to a container asks for a HOME-rooted one.

Parameters
prefixa short tag naming the caller, as lineTempName('qns') does
mountableroot under $HOME/.line rather than TMPDIR

Definition at line 84 of file tempdir.h.

References line::InputError::InputError(), and make_temp_dir().

Referenced by make_temp_dir(), line::io::qn2jsimg(), and line::util::TempDir::TempDir().

◆ method_type()

std::string line::util::method_type ( const std::string & solvername,
const std::string & method )
inline

Banner classification of a solution method.

Lookup order: "<solver>.<method>", "<method>", the tail after each dot of the method (longest suffix first), the head before its first dot, "#<solver>", then "approximate,deterministic". The unknown-method default is the conservative one: claiming exactness a method does not have is the costlier error.

Parameters
solvernamebanner solver name, with or without the "Solver" prefix
methodresolved method label, possibly carrying a "default/" prefix

Definition at line 211 of file method_type.h.

References method_type().

Referenced by method_type().

◆ run_inherit()

int line::util::run_inherit ( const std::vector< std::string > & argv)
inline

Runs a command with the parent's stdout and stderr, e.g.

so a docker pull streams its progress. There is no deadline: a pull is long by nature and the user can see it working.

Parameters
argvthe command and its arguments
Returns
the exit code, or -1 if the command could not run

Definition at line 170 of file subprocess.h.

References run_inherit().

Referenced by line::io::docker_pull(), and run_inherit().

◆ sha256_file_hex()

std::string line::util::sha256_file_hex ( const std::string & path)
inline

The digest of a file's contents, streamed.

Returns
the 64 hex characters, or an EMPTY string when the file cannot be read – which the caller must not confuse with a mismatch: a digest that could not be computed has verified nothing.

Definition at line 188 of file sha256.h.

References line::util::Sha256::hex(), sha256_file_hex(), and line::util::Sha256::update().

Referenced by sha256_file_hex().

◆ sha256_hex()

std::string line::util::sha256_hex ( const std::string & data)
inline

The digest of a byte string, as 64 lowercase hex characters.

Definition at line 175 of file sha256.h.

References line::util::Sha256::hex(), sha256_hex(), and line::util::Sha256::update().

Referenced by sha256_hex().

◆ timeout_arm()

◆ timeout_armed()

bool line::util::timeout_armed ( )
inline

Whether any budget is armed on this thread.

Definition at line 85 of file line_timeout.h.

References line::util::timeout_detail::stack(), and timeout_armed().

Referenced by timeout_armed().

◆ timeout_check()

void line::util::timeout_check ( const char * where)
inline

The raising checkpoint, for a computation with no valid partial result: throws LINE:numerical:Timeout naming where when the budget has run out.

Definition at line 124 of file line_timeout.h.

References line::NumericError::NumericError(), timeout_check(), and timeout_exceeded().

Referenced by line::qn::cartesian(), line::ssa::NrmSpaceEngine< T >::enumerate_space(), line::pfqn::pfqn_mva(), line::pfqn::pfqn_mva_ilock(), line::pfqn::pfqn_mvald(), line::pfqn::pfqn_mvaldmx(), line::ctmc::reachable_space_generator(), line::qn::space_generator(), and timeout_check().

◆ timeout_exceeded()

◆ timeout_kill_bound()

int line::util::timeout_kill_bound ( int explicit_seconds,
double grace = 30.0 )
inline

The kill bound of a child that also has a bound of its OWN (explicit_seconds, not positive = none): the tighter of the two, 0 when neither is set.

Definition at line 148 of file line_timeout.h.

References timeout_kill_bound(), and timeout_kill_seconds().

Referenced by line::jmt::jmt_run(), line::jmt::jmt_run_docker(), line::jmt::jmt_solve_rest(), and timeout_kill_bound().

◆ timeout_kill_seconds()

int line::util::timeout_kill_seconds ( double grace = 30.0)
inline

The hard kill bound of a child process under the armed budget: the remaining seconds plus grace, rounded up, as MATLAB's lineTimeoutKillPrefix builds timeout -k 5 ceil(remaining+30).

0 (wait indefinitely) when nothing is armed.

Definition at line 137 of file line_timeout.h.

References timeout_kill_seconds(), and timeout_remaining().

Referenced by line::ldes::solver_ldes_text(), timeout_kill_bound(), and timeout_kill_seconds().

◆ timeout_raise_if_killed_on_budget()

void line::util::timeout_raise_if_killed_on_budget ( const std::string & who)
inline

A child process was killed on its bound: raise LINE:numerical:Timeout when the armed budget is what ran out (a killed child wrote no result, so there is no partial one), and return otherwise so the caller reports its own bound.

Definition at line 159 of file line_timeout.h.

References line::NumericError::NumericError(), timeout_exceeded(), and timeout_raise_if_killed_on_budget().

Referenced by line::jmt::jmt_run(), line::jmt::jmt_run_docker(), line::jmt::jmt_solve_rest(), line::ldes::ldes_solve_rest(), line::ldes::solver_ldes_text(), and timeout_raise_if_killed_on_budget().

◆ timeout_remaining()

double line::util::timeout_remaining ( )
inline

◆ timeout_trip()

void line::util::timeout_trip ( )
inline

Mark the innermost budget tripped without reading the clock: for an external engine that REPORTS it stopped on the budget (LDES stoppingReason == "max_time", a JSIM run given -maxtime).

A no-op when nothing is armed.

Definition at line 115 of file line_timeout.h.

References line::util::timeout_detail::stack(), and timeout_trip().

Referenced by line::ldes::ldes_engine_solve(), line::ldes::parse_ldes_result(), line::ldes::solver_ldes_text(), and timeout_trip().

◆ timeout_tripped()

bool line::util::timeout_tripped ( )
inline

Whether the innermost budget was tripped by a checkpoint or by timeout_trip.

Definition at line 105 of file line_timeout.h.

References line::util::timeout_detail::stack(), and timeout_tripped().

Referenced by line::NetworkSolver::avg_table(), line::ldes::solver_ldes_text(), timeout_tripped(), and CliTimeoutReport::~CliTimeoutReport().

◆ timeout_warn()

void line::util::timeout_warn ( const std::string & solver,
double budget )
inline

The one warning a solve that stopped on its budget prints, MATLAB's flagTimeout text, on stderr as every other [LINE] Warning here.

Definition at line 230 of file line_timeout.h.

References timeout_warn().

Referenced by line::NetworkSolver::avg_table(), timeout_warn(), and CliTimeoutReport::~CliTimeoutReport().

◆ trim()

std::string line::util::trim ( const std::string & s)
inline

Trims ASCII whitespace from both ends, as Java's String.trim() does.

Definition at line 181 of file subprocess.h.

References trim().

Referenced by line::io::docker_has_local_image(), line::io::wfcommons_detail::fetch_https(), line::jmt::jmt_version(), line::ldes::solver_ldes_text(), line::sym::sym_resolve(), and trim().