Daemon
Use jcmsuite.daemon.handler to get the daemon handler owned by a
SolverContext. The handler starts and stops the daemon. It also controls
resources, submitted solves, and result collection.
Handler
- jcmsuite.daemon.handler(*, context=None)[source]
Return the daemon handler for a context.
- Parameters:
context (SolverContext | None, optional) – JCMsuite settings to use. If omitted, use the active context or the default context.
- Returns:
Daemon handler that belongs to the selected context.
- Return type:
- class jcmsuite.daemon.DaemonHandler(*, context)[source]
Control the JCMsuite daemon.
- Parameters:
context (SolverContext) – JCMsuite settings for the daemon.
- context
Context that supplies the daemon installation and runtime settings.
- Type:
- lifecycle
Namespace for starting, stopping, and inspecting the daemon lifecycle.
- Type:
- resources
Namespace for adding, listing, inspecting, and deleting resources.
- Type:
- jobs
Namespace for waiting on and managing daemon jobs.
- Type:
Notes
Get a handler from jcmsuite.daemon.handler(…). If you use the handler in a with block, the block starts and connects the daemon. The block also disconnects and stops the daemon when the block ends.
- connect()[source]
Connect the handler to the daemon.
This method starts the daemon first if necessary. It also registers resources that were added before the connection.
- Returns:
The handler is connected to the daemon.
- Return type:
None
- disconnect()[source]
Disconnect from the daemon without removing resource settings.
- Returns:
The connection is closed. Registered resource settings remain in the handler.
- Return type:
None
- shutdown()[source]
Disconnect and stop the JCMsuite daemon.
- Returns:
The daemon is stopped.
- Return type:
None
- start()[source]
Start the JCMsuite daemon service.
- Returns:
The daemon service is ready for a connection.
- Return type:
None
- Raises:
RuntimeContextError – If JCMsolve is not available.
- status()[source]
Return the current daemon status.
- Returns:
Information about the connection and registered resources.
- Return type:
- wait(submission, *, asynchronous=False, break_when='all', timeout=None, on_timeout='raise', on_error='raise', progress=False, progress_label=None)[source]
Wait for a daemon submission and return its results.
- Parameters:
submission (SolveSubmission | BatchSolveSubmission) – submission returned by solve(…, dispatch=”submit”).
asynchronous (bool, optional) – If True, return a value that you must use with await.
break_when ({"all", "any"}, optional) – Completion condition. “all” waits for all requested solves. “any” returns after the first requested solve finishes.
timeout (float | None, optional) – Maximum number of seconds to wait. If omitted, wait without a time limit.
on_timeout ({"raise", "return"}, optional) – Action at the time limit. “raise” raises an error. “return” returns the results that are available.
on_error ({"raise", "collect"}, optional) – Action for a failed batch entry. “raise” raises an error. “collect” stores the failure in the batch result.
progress (bool, optional) – If True, show progress for a batch wait.
progress_label (str | None, optional) – Label for the progress display.
- Returns:
Result that matches the submission. If asynchronous=True, return a value that you must use with await.
- Return type:
SolveResult | BatchSolveResult | Coroutine[…]
- Raises:
ConfigMappingError – If the daemon reports an input error with a source position. The SolveExecutionError cause retains the solver diagnostics.
SolveExecutionError – If a solve fails and on_error is “raise”. The traceback omits deep internal daemon frames.
- class jcmsuite.daemon.models.DaemonStatus(started, connected, resources, daemon_payload=None)[source]
Daemon status snapshot.
- Parameters:
started (bool) – Whether the daemon lifecycle has been started.
connected (bool) – Whether the handler currently represents an active daemon connection.
resources (tuple[DaemonResource, ...]) – Configured resources known to this handler.
daemon_payload (object | None) – Optional raw status payload returned by the daemon backend.
- connected
Whether the handler represents an active daemon connection.
- daemon_payload
Optional raw status payload returned by the daemon backend.
- property resource_count
Return number of configured resources.
- resources
Configured resources known to this handler.
- started
Whether the daemon lifecycle has been started.
Lifecycle Namespace
Use handler.lifecycle to start the daemon,
get its status, or stop it.
- class jcmsuite.daemon.namespaces.DaemonLifecycle(*, handler)[source]
Lifecycle namespace facade.
- shutdown()[source]
Disconnect and stop the daemon.
- Returns:
The daemon is stopped.
- Return type:
None
- startup()[source]
Start the daemon and connect the handler.
- Returns:
The handler is connected to the running daemon.
- Return type:
None
Submission Namespace
Use handler.jobs to wait for
submissions or manage daemon-dispatched solves.
- class jcmsuite.daemon.namespaces.DaemonJobs(*, handler)[source]
Jobs namespace facade.
- info(job_ids=None, *, status_only=False)[source]
Return information about submitted daemon solves.
- Parameters:
job_ids (Sequence[str | int] | None, optional) – Daemon submission identifiers to select. If omitted, select all known daemon submissions.
status_only (bool, optional) – If True, request only status information when the daemon supports this option.
- Returns:
Information supplied by the daemon. The available fields depend on the daemon version.
- Return type:
object
- kill(job_ids=None)[source]
Stop submitted daemon solves.
- Parameters:
job_ids (Sequence[str | int] | None, optional) – Daemon submission identifiers to stop. If omitted, stop all known daemon submissions.
- Returns:
Identifiers of the stopped daemon jobs.
- Return type:
tuple[int, …]
- wait(submission, *, asynchronous=False, break_when='all', timeout=None, on_timeout='raise', on_error='raise', progress=False, progress_label=None)[source]
Wait for a daemon submission and return its results.
- Parameters:
submission (SolveSubmission | BatchSolveSubmission) – submission returned by solve(…, dispatch=”submit”).
asynchronous (bool, optional) – If True, return a value that you must use with await.
break_when ({"all", "any"}, optional) – Condition that ends a batch wait. “all” waits for all requested solves. “any” returns after the first requested solve finishes.
timeout (float | None, optional) – Maximum number of seconds to wait. If omitted, wait without a time limit.
on_timeout ({"raise", "return"}, optional) – Action at the time limit. “raise” raises an error. “return” returns the results that are available.
on_error ({"raise", "collect"}, optional) – Action for a failed batch entry. “raise” raises an error. “collect” stores a BatchSolveFailure in the batch result.
progress (bool, optional) – If True, show progress while waiting for a batch.
progress_label (str | None, optional) – Text to show with the progress display. If omitted, use “daemon.wait”.
- Returns:
Result that matches the submission. If asynchronous=True, return a value that you must use with await.
- Return type:
SolveResult | BatchSolveResult | Coroutine[…]
Resource Namespace
Use handler.resources to add, inspect, or
remove compute resources.
- class jcmsuite.daemon.resources.DaemonResources(*, handler)[source]
Resource namespace facade for daemon resource management.
- Parameters:
handler (DaemonHandler) – Owning daemon handler instance.
- add(resource)[source]
Add one compute resource to the daemon.
- Parameters:
resource (Workstation | Cluster | Queue | SlurmNodes) – Workstation, cluster, queue, or active SLURM allocation to add.
- Returns:
Added resource.
- Return type:
Workstation | Cluster | Queue | SlurmNodes
- Raises:
InvalidConfigurationError – If the resource settings are not valid.
- delete(*, kind=None, hostname=None, allow_many=False)[source]
Delete resources that match the filters.
- Parameters:
kind ({"workstation", "cluster", "queue", "slurm"} | None, optional) – Resource type to select. If omitted, select all resource types.
hostname (str | None, optional) – Hostname to select. If omitted, select all hostnames.
allow_many (bool, optional) – If True, allow the method to delete multiple matching resources.
- Returns:
Removed resources in the order in which they were added. Return an empty tuple if no resource matches.
- Return type:
tuple[Workstation | Cluster | Queue | SlurmNodes, …]
- Raises:
InvalidConfigurationError – If multiple resources match and allow_many is False.
- info(*, kind=None, hostname=None)[source]
Return information for resources that match the filters.
- Parameters:
kind ({"workstation", "cluster", "queue", "slurm"} | None, optional) – Resource type to select. If omitted, select all resource types.
hostname (str | None, optional) – Hostname to select. If omitted, select all hostnames.
- Returns:
Information supplied by the daemon. If the handler is not connected, return the matching resource settings.
- Return type:
object
- list(*, kind=None, hostname=None)[source]
Return registered resources that match the filters.
- Parameters:
kind ({"workstation", "cluster", "queue", "slurm"} | None, optional) – Resource type to select. If omitted, select all resource types.
hostname (str | None, optional) – Hostname to select. If omitted, select all hostnames.
- Returns:
Matching resources in registration order.
- Return type:
tuple[Workstation | Cluster | Queue | SlurmNodes, …]
Resource Models
- class jcmsuite.daemon.Workstation(hostname, login=None, ssh_client=None, pem_file=None, ssh_agent_forwarding=None, ssh_timeout_s=None, jcm_root=None, multiplicity=1, n_threads=1, gpus=None, working_dir='', ooc_dir=None, max_core_size_mb=None, memory_limit_mb=None, license_server_port=None)[source]
Describe a workstation that can run solves.
- Parameters:
hostname (str | Sequence[str]) – Workstation name. For a connection through other hosts, give the host names in connection order.
login (str | Sequence[str | None] | None, optional) – User name for each host in the connection path.
ssh_client (str | Sequence[str | None] | None, optional) – Secure Shell (SSH) program for each host in the connection path.
pem_file (Path | str | Sequence[Path | str | None] | None, optional) – SSH private-key file in PEM format for each host in the connection path.
ssh_agent_forwarding (bool | None, optional) – If True, enable SSH agent forwarding.
ssh_timeout_s (int | None, optional) – SSH connection timeout in seconds.
jcm_root (Path | str | None, optional) – JCMsuite installation directory on the workstation. Pass a remote path as a string; its spelling is preserved without client-side path resolution.
multiplicity (int, optional) – Maximum number of solves that can run at the same time.
n_threads (int, optional) – Number of solver threads for each solve.
gpus (Literal["all", "no"] | int | Sequence[int] | None, optional) – GPUs to use. Use “all” for all available GPUs. Use “no” to disable GPU use. Give one identifier or an ordered collection of identifiers to select specific GPUs.
working_dir (Path | str, optional) – Directory in which the workstation runs solves.
ooc_dir (Path | str | None, optional) – Optional out-of-core directory.
max_core_size_mb (int | None, optional) – Maximum memory for each solver core in megabytes.
memory_limit_mb (int | None, optional) – Maximum total solver memory in megabytes.
license_server_port (int | None, optional) – Network port for license-server forwarding.
- class jcmsuite.daemon.ClusterNode(hostname, jcm_root=None, memory_limit_mb=None, gpu=None)[source]
Describe one compute node in a cluster.
- Parameters:
hostname (str) – Node name used from the cluster access host.
jcm_root (Path | str | None, optional) – JCMsuite installation directory on this node. Pass a remote path as a string; its spelling is preserved without client-side path resolution.
memory_limit_mb (int | None, optional) – Maximum solver memory on this node in megabytes.
gpu (int | None, optional) – Graphics processing unit (GPU) identifier to use on this node. One ClusterNode can select one GPU. To select multiple GPUs on one node, add one ClusterNode for each GPU identifier.
- class jcmsuite.daemon.Cluster(hostname, nodes, login=None, ssh_client=None, pem_file=None, ssh_agent_forwarding=None, ssh_timeout_s=None, jcm_root=None, multiplicity=1, n_threads=1, working_dir='', ooc_dir=None, max_core_size_mb=None, license_server_port=None)[source]
Describe a cluster that can run solves.
- Parameters:
hostname (str | Sequence[str]) – Cluster access host. For a connection through other hosts, give the host names in connection order.
nodes (Sequence[ClusterNode]) – Compute nodes that belong to the cluster.
login (str | Sequence[str | None] | None, optional) – User name for each host in the connection path.
ssh_client (str | Sequence[str | None] | None, optional) – Secure Shell (SSH) program for each host in the connection path.
pem_file (Path | str | Sequence[Path | str | None] | None, optional) – SSH private-key file in PEM format for each host in the connection path.
ssh_agent_forwarding (bool | None, optional) – Enable or disable SSH agent forwarding.
ssh_timeout_s (int | None, optional) – SSH connection timeout in seconds.
jcm_root (Path | str | None, optional) – JCMsuite installation root on the cluster. Pass a remote path as a string; its spelling is preserved without client-side path resolution.
multiplicity (int, optional) – Maximum number of solves that can run at the same time.
n_threads (int, optional) – Number of threads for each submitted solve.
working_dir (Path | str, optional) – Working directory on the cluster.
ooc_dir (Path | str | None, optional) – Out-of-core directory on the cluster.
max_core_size_mb (int | None, optional) – Maximum memory for each solver core in megabytes.
license_server_port (int | None, optional) – Port for license-server forwarding.
- class jcmsuite.daemon.Queue(hostname, queue_type='slurm', login=None, ssh_client=None, pem_file=None, ssh_agent_forwarding=None, ssh_timeout_s=None, jcm_root=None, multiplicity=10, account='', job_name='', partition_name='', n_nodes=None, n_tasks=None, n_tasks_per_node=None, node_list='', exclude_node='', cmd_line_args='', working_dir='', n_threads=1, gpu_type=None, n_gpus=None, gres=None, time_minutes=None, features=None, exclusive=None, memory_per_job_mb=None, ooc_dir=None, max_core_size_mb=None, environment=None, remote_daemon_port=None, remote_daemon_signature=None)[source]
Describe a SLURM queue that can run solves.
- Parameters:
hostname (str | Sequence[str]) – Queue access host. For a connection through other hosts, give the host names in connection order.
queue_type ({"slurm"}, optional) – Queue scheduler type.
login (str | Sequence[str | None] | None, optional) – User name for each host in the connection path.
ssh_client (str | Sequence[str | None] | None, optional) – Secure Shell (SSH) program for each host in the connection path.
pem_file (Path | str | Sequence[Path | str | None] | None, optional) – SSH private-key file in PEM format for each host in the connection path.
ssh_agent_forwarding (bool | None, optional) – Enable or disable SSH agent forwarding.
ssh_timeout_s (int | None, optional) – SSH connection timeout in seconds.
jcm_root (Path | str | None, optional) – JCMsuite installation root on the queue system. Pass a remote path as a string; its spelling is preserved without client-side path resolution.
multiplicity (int, optional) – Maximum number of solves that can run at the same time.
account (str, optional) – SLURM account name.
job_name (str, optional) – SLURM job name.
partition_name (str, optional) – SLURM partition name.
n_nodes (int | None, optional) – Number of requested nodes.
n_tasks (int | None, optional) – Number of requested tasks.
n_tasks_per_node (int | None, optional) – Number of requested tasks on each node.
node_list (str, optional) – SLURM node-list expression.
exclude_node (str, optional) – SLURM node-exclusion expression.
cmd_line_args (str, optional) – Additional options for the SLURM command.
working_dir (Path | str, optional) – Working directory on the queue system.
n_threads (int, optional) – Number of threads for each submitted solve.
gpu_type (str | None, optional) – Requested GPU type.
n_gpus (int | None, optional) – Number of requested GPUs.
gres (str | None, optional) – SLURM generic resource (GRES) setting.
time_minutes (float | int | None, optional) – Queue time limit in minutes.
features (str | None, optional) – Required SLURM node features.
exclusive (bool | None, optional) – Request exclusive node allocation.
memory_per_job_mb (int | None, optional) – Memory limit for each job in megabytes.
ooc_dir (Path | str | None, optional) – Out-of-core directory on the queue system.
max_core_size_mb (int | None, optional) – Maximum memory for each solver core in megabytes.
environment (str | None, optional) – Environment setup command or script.
remote_daemon_port (int | None, optional) – Port of an existing remote daemon.
remote_daemon_signature (str | None, optional) – Signature of an existing remote daemon.
- class jcmsuite.daemon.SlurmNodes(task_ids=None, cluster=False)[source]
Use compute nodes from the current SLURM allocation.
- Parameters:
task_ids (Sequence[int] | set[int] | int | None, optional) – SLURM task identifiers to use. If omitted, use the current allocation.
cluster (bool, optional) – If True, use the allocation as one Message Passing Interface (MPI) cluster. If False, use the allocation as separate workers.
Notes
The daemon registers this resource on localhost and uses one scheduler slot. These settings cannot be changed.