gcubed.linearisation.workspace_planning
Deterministic memory planning for state-space-form block operations.
The planner derives a hard workspace ceiling from current system, cgroup, and optional process-limit headroom. A configured cap and an offline host performance profile may reduce that ceiling, but neither can increase it. The safety decision remains active when optional memory profiling is disabled.
Share of effective additional memory kept outside SSF workspaces.
Minimum machine reserve used when five percent would be smaller.
Per-thread fallback used when no matching host calibration is loaded.
Supported local workspace-performance profile schema.
Legacy workspace exception retained for API compatibility.
Valid nonempty operations now attempt at least one column after reporting
an estimated shortfall. Invalid planner inputs still raise ValueError.
One measured operation-shape preference from a local host profile.
Attributes: operation: Stable numerical-operation name. dtype: NumPy dtype string used by the operation. layout: Stable description of relevant array layouts. row_count: Result or right-hand-side row count. inner_dimension: Matrix inner dimension, or LU factor order. calibrated_columns: Full operation width used by calibration. preferred_block_columns: Speed-preferred measured block width. preferred_workspace_bytes: Measured speed-preferred workspace ceiling. source_model_id: Build-197 model supplying the representative shape.
Versioned host-local operation preferences loaded before model solve.
Attributes: source_path: Profile file used by this process. blas_signature: Stable signature of calibrated BLAS libraries. blas_thread_count: Active BLAS thread count during calibration. blas_workspace_bytes_per_thread: Calibrated fixed BLAS allowance. preferences: Representative operation-shape preferences.
Return the nearest validated preference for an operation shape.
Args: estimate: Current operation metadata and workspace estimate. total_columns: Full or remaining operation width.
Returns:
Preferred workspace and a reproducible source description, or
None when no profile shape is sufficiently close.
Raises:
ValueError: Raised when total_columns is not positive.
Memory ceilings used for every state-space-form block operation.
Attributes:
workspace_cap_bytes: Optional user upper bound for one block. None
selects a completely automatic machine-headroom ceiling.
process_memory_limit_bytes: Optional target process RSS ceiling.
performance_profile: Optional validated host-local speed preferences.
Return matching host-calibrated or fallback BLAS workspace.
Args: blas_signature: Stable signature of active BLAS libraries. blas_thread_count: Active BLAS thread count.
Returns: Bytes reserved per active BLAS thread.
Raises: ValueError: Raised when the signature is empty or thread count is not positive.
Current process and machine memory values used by the planner.
Attributes:
rss_bytes: Current resident set size of this process.
peak_rss_bytes: Process high-water resident set size.
system_available_bytes: Linux MemAvailable when present.
cgroup_available_bytes: Remaining finite cgroup memory allowance.
effective_available_bytes: Minimum available value from applicable
system and cgroup sources.
effective_available_source: Source that limited effective availability.
Fixed and per-column memory estimates for one numerical operation.
Attributes: operation: Stable operation name used in profiler events. fixed_workspace_bytes: Workspace independent of block width. result_bytes_per_column: Newly resident result bytes per column. temporary_output_bytes_per_column: Independently allocated numerical output bytes per column. reusable_output_bytes_per_column: Reusable output-buffer bytes per column. packing_bytes_per_column: Conservative LAPACK or BLAS packing bytes per column. blas_workspace_bytes: Portion of fixed workspace assigned to BLAS. dtype: NumPy result dtype string used for performance-profile matching. layout: Stable relevant-array layout description. row_count: Output or right-hand-side rows for this operation. inner_dimension: Matrix inner dimension, or LU factor order. blas_signature: Stable active-library signature. blas_thread_count: Active BLAS thread count.
Machine-derived capacity and performance planning ceilings.
Attributes:
effective_additional_headroom_bytes: Smallest reliable machine or
process-limit capacity above current RSS.
effective_additional_headroom_source: Capacity source defining that
value.
hard_workspace_ceiling_bytes: Smallest raw machine, process, or user
workspace limit before planning reserves are subtracted. The
legacy hard name identifies the source; an estimated shortfall
is now advisory.
hard_workspace_ceiling_source: Source defining that raw limit.
machine_reserve_bytes: Dynamic memory retained outside model work.
conservative_nonworkspace_bytes: Phase demand still expected above
current RSS.
automatic_hard_ceiling_bytes: Capacity left after reserve and phase
demand, before optional user/performance limits.
performance_preferred_workspace_bytes: Matching offline preference.
performance_preference_source: Profile sample used for the preference.
selected_workspace_bytes: Final ceiling used to calculate block width.
limiting_constraint: Constraint defining the selected ceiling.
Selected width and evidence for one block operation.
Attributes:
estimate: Operation-specific workspace estimate.
configuration: Active memory ceilings.
memory: Memory values sampled for this decision.
budget: Machine-derived workspace budget for this decision.
total_columns: Columns remaining in the operation.
maximum_columns: Shrink-only width ceiling inherited from the operation.
block_columns: Selected number of columns for this block.
safe_workspace_bytes: Ordinary policy ceiling before any one-column
progress-floor attempt.
one_column_workspace_bytes: Estimated bytes needed for minimum
progress.
minimum_progress_floor_applied: Whether execution borrowed from a
planning reserve to select one column.
policy_workspace_shortfall_bytes: Bytes by which the ordinary policy
ceiling missed the one-column requirement.
hard_workspace_shortfall_bytes: Bytes by which measured or configured
raw headroom missed one column, or None when raw capacity is
unavailable.
memory_estimate_exceeded: Whether the selected one-column attempt
exceeds an ordinary policy or raw-capacity estimate.
estimated_workspace_bytes: Estimated workspace for the selected block.
estimated_process_peak_bytes: Current RSS plus estimated workspace.
limiting_constraint: Source defining the ordinary policy ceiling.
width_limiting_constraint: Reason the selected width cannot be larger.
Return validated state-space-form workspace settings.
Args: None.
Returns: Automatic configuration with optional user upper bounds and a validated local performance profile.
Raises: ValueError: Raised when a configured GiB value is malformed, nonfinite, negative, or zero where a positive value is required.
Return a stable signature for active BLAS implementations.
Args:
thread_pools: Values returned by :func:threadpoolctl.threadpool_info.
Returns: Canonical JSON containing the library implementation, version, architecture, and threading layer for each BLAS pool. Thread counts are excluded because they are stored separately in the profile key.
Raises: TypeError: Raised when a value cannot be JSON serialized.
Load and validate a versioned local performance profile.
Args: path: JSON profile path produced by the host-calibration command.
Returns: Immutable validated performance profile.
Raises:
FileNotFoundError: Raised when path is absent.
OSError: Propagated when the file cannot be read.
json.JSONDecodeError: Raised when the file is not valid JSON.
TypeError: Raised when the JSON root or preferences have invalid types.
ValueError: Raised for an unsupported schema or invalid field value.
KeyError: Raised when a required field is absent.
Read current process, system, and cgroup memory values.
Args: None.
Returns: Snapshot using the minimum finite system or cgroup availability as the effective available memory.
Raises:
No deliberate exceptions are raised. Missing or unreadable Linux files
are represented by None fields.
Calculate the hard and speed-preferred workspace ceilings.
Args: configuration: Optional user upper bounds and local performance data. estimate: Current operation metadata used for profile matching. total_columns: Columns remaining in the operation. memory: Current process and machine memory snapshot. conservative_nonworkspace_bytes: Phase memory still expected to be allocated above current RSS.
Returns: Reproducible capacity, reserve, preference, and selected workspace.
Raises: ValueError: Raised for nonpositive columns or negative phase demand.
Return the calibrated reserve for current effective headroom.
Args: effective_headroom_bytes: Smallest reliable additional capacity.
Returns: The larger of 512 MiB and five percent of effective headroom, with the percentage result rounded upward to a whole byte.
Raises: ValueError: Raised when headroom is negative.
Select a positive block using active memory estimates.
Args: configuration: Configured workspace, reserve, and process ceilings. estimate: Operation-specific fixed and per-column estimates. total_columns: Columns remaining in the operation. maximum_columns: Optional shrink-only ceiling from an earlier decision. memory: Optional injected memory snapshot, primarily for deterministic tests. Current values are read when omitted. conservative_nonworkspace_bytes: Phase demand still expected above current RSS and therefore unavailable to this operation.
Returns: A block plan containing every input needed to reproduce the decision.
Raises: ValueError: Raised when column counts are not positive. Estimated shortfalls remain visible in the returned plan and select a one-column attempt.