Context
The context API selects the JCMsuite installation and the default execution
method. A context= argument takes precedence over the context for the current
scope. The context for the current scope takes precedence over the default
context.
Configuration Types
- jcmsuite.context.BackendMode = Literal["auto", "local", "daemon"]
Execution method selected by a context or solve call. Accepts “auto”, “local”, or “daemon”.
- jcmsuite.context.GPUSelection = Literal["all", "no"] | int | Sequence[int]
GPU selection accepted by a local context. Accepts “all”, “no”, one non-negative GPU index, or a sequence of such indices.
Create And Resolve Contexts
Public runtime context API for jcmsuite.
- jcmsuite.context.create_context(*, jcm_root=None, backend_mode='auto', num_threads=None, memory_limit_mb=None, gpus=None, temp_dir_root=None, debug=False, logging_level=None, log_dir=None, skip_logger=False)[source]
Create a set of JCMsuite settings.
- Parameters:
jcm_root (str | Path | None, optional) – JCMsuite installation root. If omitted, use the JCMROOT environment variable.
backend_mode (Literal["auto", "local", "daemon"], optional) – Default execution method for solve(…).
num_threads (int | None, optional) – Number of solver threads.
memory_limit_mb (int | None, optional) – Solver memory limit in megabytes.
gpus (GPUSelection | None, optional) – Local GPU selection. Use
"all"or"no". You can also give one non-negative GPU identifier or a non-empty sequence of GPU identifiers.temp_dir_root (str | Path | None, optional) – Directory in which JCMsuite creates temporary working directories.
debug (bool, optional) – If True, enable debug logging.
logging_level (int | None, optional) – Amount of information to write to the log.
log_dir (Path | None, optional) – Directory for log files.
skip_logger (bool, optional) – If True, do not configure logging during context creation.
- Returns:
New JCMsuite settings.
- Return type:
- jcmsuite.context.get_current_context()[source]
Return the context for the current scope.
- Returns:
Active scoped context, or None if no scoped context is active.
- Return type:
SolverContext | None
- jcmsuite.context.get_default_context()[source]
Return the default JCMsuite settings.
- Returns:
Default context. If no default context exists, create one.
- Return type:
- jcmsuite.context.reset_default_context()[source]
Remove the default JCMsuite settings.
- Returns:
This function has no return value.
- Return type:
None
- jcmsuite.context.resolve_context(context=None)[source]
Select the JCMsuite settings for an operation.
- Parameters:
context (SolverContext | None, optional) – Settings supplied directly to the operation.
- Returns:
Selected context. An explicit context has first priority. A context from the current scope has second priority. The default context has last priority.
- Return type:
- jcmsuite.context.set_default_context(context)[source]
Set the default JCMsuite settings.
- Parameters:
context (SolverContext) – Settings to use when a function does not receive context=.
- Returns:
This function has no return value.
- Return type:
None
SolverContext
- class jcmsuite.context.SolverContext(*, jcm_root_dir=None, backend_mode='auto', num_threads=None, memory_limit_mb=None, gpus=None, temp_dir_root=None, debug=False, skip_logger=False, logging_level=None, log_dir=None)[source]
Store settings for JCMsuite operations.
- Parameters:
jcm_root_dir (Path | None, optional) – JCMsuite installation root. If omitted, use the JCMROOT environment variable.
backend_mode (Literal["auto", "local", "daemon"], optional) – Default execution method for solve(…).
num_threads (int | None, optional) – Number of solver threads.
memory_limit_mb (int | None, optional) – Solver memory limit in megabytes.
gpus (GPUSelection | None, optional) – Local GPU selection. Use
"all"or"no". You can also give one non-negative GPU identifier or a non-empty sequence of GPU identifiers.temp_dir_root (Path | None, optional) – Directory in which JCMsuite creates temporary working directories.
debug (bool, optional) – If True, enable debug logging.
skip_logger (bool, optional) – If True, do not configure logging.
logging_level (int | None, optional) – Amount of information to write to the log.
log_dir (Path | None, optional) – Directory for jcmsuite.log.
- info(*, print=True, verbose=False)[source]
Return installation, system, and license information.
- Parameters:
print (bool, optional) – If True, show the information in the terminal.
verbose (bool, optional) – If True, also show the interface build time and Git commit identifier.
- Returns:
Installation, computer, interface, and license information.
- Return type:
- Raises:
RuntimeError – If asynchronous code calls this method before startup() is complete.
- async startup()[source]
Load the JCMsuite installation and license information.
Call this method with await before you use info() in asynchronous code. A second call reuses the information from the first call.
- Returns:
This method has no return value.
- Return type:
None
- Raises:
RuntimeContextError – If the JCMsuite installation is not configured, JCMsolve is not available, or installation or license information cannot be read.
- property installation
Return the JCMsuite installation information.
Call startup() before you read this property.
- Returns:
Installed JCMsuite version and directory.
- Return type:
- Raises:
RuntimeContextError – If startup() has not loaded the installation information.
- property jcm_root
Return the JCMsuite installation directory.
- Returns:
Installation directory, or None if JCMsuite is not configured.
- Return type:
Path | None
- property license
Return the JCMsuite license information.
Call startup() before you read this property.
- Returns:
Active JCMsuite license information.
- Return type:
- Raises:
RuntimeContextError – If startup() has not loaded the license information.
- property system
Return the computer and solver settings.
- Returns:
Detected computer information and configured solver limits.
- Return type:
Information Models
- class jcmsuite.context.JCMInfoDetails(installation, interface, system, license)[source]
Information returned by jcmsuite.info(…).
- installation
Installed JCMsuite version and directory.
- Type:
- interface
Installed jcmsuite interface version and build information.
- Type:
- system
Computer information and solver settings.
- Type:
- license
Active JCMsuite license information.
- Type:
- class jcmsuite.context.JCMInterfaceDetails(package_name, version=None, git_commit_sha=None, git_commit_sha_source='unknown', build_timestamp=None)[source]
Information about the installed jcmsuite Python interface.
- package_name
Installed package name.
- Type:
str
- version
Installed package version.
- Type:
str | None
- git_commit_sha
Git commit identifier for the package build, if known.
- Type:
str | None
- git_commit_sha_source
Source of git_commit_sha. The value is “embedded”, “environment”, “git”, or “unknown”.
- Type:
str
- build_timestamp
Package build date and time in ISO 8601 UTC format, if known.
- Type:
str | None
- class jcmsuite.context.JCMInstallationDetails(jcm_root, version=None, buildtag=None)[source]
Information about the installed JCMsuite version.
- jcm_root
JCMsuite installation directory.
- Type:
Path
- version
JCMsuite version reported by JCMsolve –version.
- Type:
str | None
- buildtag
JCMsuite build tag reported by JCMsolve –version.
- Type:
str | None
- class jcmsuite.context.JCMLicenseDetails(period, file=None, server=None)[source]
Information about the active JCMsuite license.
- period
License period reported by JCMsuite.
- Type:
str
- file
License file, if JCMsuite uses a license file.
- Type:
Path | None
- server
License server address, if JCMsuite uses a license server.
- Type:
str | None
- class jcmsuite.context.JCMSystemDetails(os, n_cores, binext, n_threads=None, nodes=None, ooc_dir=None, temp_dir_root=None, max_core_size_mb=None, max_memory_mb=None, gpu_usage=None)[source]
Computer information and solver settings.
- os
Operating system name.
- Type:
str
- n_cores
Number of detected CPU cores.
- Type:
int
- binext
Program file extension. The value is .exe on Windows and an empty string on Linux.
- Type:
str
- n_threads
Number of solver threads, or None to use the JCMsuite default.
- Type:
int | None
- nodes
Compute nodes for distributed solves, if configured.
- Type:
str | None
- ooc_dir
Directory for out-of-core data, if configured.
- Type:
Path | None
- temp_dir_root
Directory that contains temporary working directories.
- Type:
Path | None
- max_core_size_mb
Maximum memory for each solver core in megabytes.
- Type:
int | None
- max_memory_mb
Maximum total solver memory in megabytes.
- Type:
int | None
- gpu_usage
Local GPU selection as
"all","no", or a comma-separated list of GPU identifiers.Nonemeans no context-specific selection.- Type:
str | None