Manufacturing Sector¶
Purpose: The ManufacturingSector manages all In-Situ Resource Utilization (ISRU) operations on the lunar base. It orchestrates a fleet of unified ISRU robots to produce essential resources like Helium-3, water, and metals. The sector operates as an intelligent, demand-driven factory, automatically prioritizing tasks based on the current stock levels of critical resources and fulfilling requests from other sectors.
Core Components:
ISRUAgent: A versatile agent that can be configured to perform various tasks, including ice extraction, regolith processing, and Helium-3 generation. Each mode has distinct power requirements and resource outputs.BufferTarget: A data object that defines the desired inventory level for a specific resource, withminandmaxthresholds. These targets drive the sector’s entire decision-making process.TaskDefinition: Maps an abstract task (e.g.,TaskType.WATER) to a specificISRUAgentoperational mode (e.g.,ICE_EXTRACTION) and its primary resource output. Theisru_modefield can also be set per-task from config (seecustom_tasksbelow), so new tasks don’t require a code change.StockFlow: A transaction object that represents any change in resources. It ensures that all resource generation, consumption, and allocation within a single step are processed atomically, preventing race conditions and ensuring data integrity.ResourceRequest: A data object representing a request for a specific amount of a resource from another sector.
Shared Enums: Resource stock keys (ResourceType) and metric contribution types (MetricContributionType) live in world_system_defs.py rather than as hardcoded strings, so the manufacturing, transportation, and ISRU code all refer to the same constants.
Operational Cycle & Key Algorithms¶
The sector’s logic is a sophisticated loop of assessing needs, assigning tasks, and processing results.
A. Deficiency-Driven Task Prioritization (_calculate_task_priorities)
This is the core decision-making algorithm. It determines which resources are most needed and by how much.
For each resource with a defined
BufferTarget, it calculates thedeficiency.\[\text{Deficiency} = \max(0, \text{Target}_{\min} - \text{Stock}_{\text{current}})\]It returns
(task, deficiency)pairs sorted from the largest deficiency to the smallest. The magnitude is kept (not just the ordering) because task assignment uses it to decide how many robots a task deserves, not just whether it goes first.
B. Power-Gated Task Planning (_plan_task_assignment)
WorldSystem.step() asks every sector for its power demand before calling any sector’s step(). Since a robot’s power demand depends on its currently assigned mode, task assignment has to happen during get_power_demand() rather than at the top of step() — otherwise the demand reported for this step’s power allocation would reflect last step’s assignment instead of the one that’s about to run.
_plan_task_assignment() is idempotent per model step (guarded by model.steps), so it’s safe to call from both get_power_demand() and step(): the real planning happens once, during whichever is called first (normally get_power_demand()), and step()’s call becomes a no-op unless the sector is stepped standalone (e.g. in tests).
C. Task Assignment (_assign_agents_to_tasks)
With a prioritized, weighted task list, the sector splits its fleet across tasks and runs them in priority order:
Proportional slots (
_allocate_task_slots): The number of robots given to each task is proportional to its share of total deficiency, using the largest-remainder method so slot counts are whole numbers that always sum to the robot count. A task with twice the deficiency of another gets roughly twice the robots, instead of capping at one robot regardless of urgency.Capability matching: Robots are only assigned to a task if the task’s ISRU mode is in that robot’s
config.isru_modeslist. A robot incapable of the most urgent task is left available for the next one down the priority list rather than being force-assigned (or skipped entirely).Priority-ordered execution: The order robots are assigned in is recorded as the step’s execution order.
step()iterates robots in that order rather than raw fleet order, so if allocated power falls short of total demand, it’s the lowest-priority task’s robots that go unpowered first.
D. Resource Request Fulfillment (_process_buffered_resource_requests)
The sector manages an incoming queue of ResourceRequest events from other sectors.
It checks if the current stock is sufficient to fulfill a pending request, tracking a per-resource running balance for the pass so multiple requests for the same resource in one step are checked against each other, not all against the same un-decremented stock (which could otherwise let combined requests exceed what’s actually on hand).
If sufficient, it creates a
StockFlowtransaction to deduct the resource from its inventory and allocate it to the requesting sector. An event is then published to notify the recipient.If not, the request remains in the queue to be re-evaluated in the next step.
E. Probabilistic Throttling & Operation
When executing the step, the sector can be throttled by the PolicyEngine.
For each robot, a random number is checked against the
robot_throttlefactor. If the number is less than the factor, the robot is marked asTHROTTLEDand skips its operation for that step.If a robot is not throttled and has enough allocated power, it performs its operation, which generates a
StockFlowobject detailing the resources produced.
F. Atomic Stock Flow Processing (process_all_stock_flows)
At the end of the step, all StockFlow objects generated during the step (from robot operations and resource allocations) are processed in a single, atomic block. This guarantees that all additions and subtractions to the resource stocks are finalized before the next simulation step begins.
Equations¶
He-3 Generation: The amount of Helium-3 generated \(He3_{\text{output}}\) is calculated using a probabilistic concentration and the robot’s throughput.
Where:
\(C_{\text{He3}}\) is the randomly determined concentration in parts-per-billion for that step.
\(\text{Throughput}_{\text{tons}}\) is the mass of regolith the robot can process per step.
Robot Slot Allocation: Each task’s share of the fleet is proportional to its share of total deficiency across all deficient tasks:
Each task gets floor(Slots_raw) robots; any robots left over (so the total adds up to Robots_total) go to the tasks with the largest fractional remainder, most urgent first.
Metric Contributions¶
A sector can report configured metrics (e.g., dust coverage) without needing a bespoke code path per metric. _create_metric_map() reads each isru_robots[].config.metric_contributions entry and, for any entry whose contribution_type is MetricContributionType.PREDEFINED ("predefined"), multiplies its contribution_value by the number of currently OPERATIONAL robots. Contribution logic is skipped entirely (returns an empty map) if the sector has no configured ISRU robots, rather than assuming at least one config entry exists.
Configuration Options¶
The sector is configured in the world_system JSON file, defining its robot fleet, initial stocks, and resource targets.
"manufacturing": {
"sector_name": "manufacturing",
"initial_stocks": {
"H2O_kg": 5.0,
"He3_kg": 10.0
},
"buffer_targets": {
"He3_kg": { "min": 20.0, "max": 300.0 },
"H2O_kg": { "min": 2.0, "max": 10.0 }
},
"custom_tasks": [
{
"name": "water",
"primary_output": "H2O_kg",
"isru_mode": "ICE_EXTRACTION"
}
],
"isru_robots": [
{
"quantity": 4,
"config": {
"ice_extraction_power_kWh": 5.0,
"ice_extraction_output_kg": 20.0,
"regolith_extraction_power_kWh": 10.0,
"he3_extraction_power_kWh": 50.0
},
"metric_contributions": [
{
"metric_id": "IND-DUST-COV",
"contribution_type": "predefined",
"contribution_value": 0.01
}
]
}
]
}
custom_tasks entries override or add to the built-in DEFAULT_TASKS (HE3, WATER, REGOLITH) by task name; each needs a matching TaskType member and, for the sector to actually plan work for it, an isru_mode that some robot’s config.isru_modes includes.
TODO: Potential Improvements¶
[ ] Implement Electrolysis: Add an
ELECTROLYSIStask and ISRU mode consumingH2O_kgand power to produceH2_kgandO2_kg.[ ] Add Resource Consumption for Extraction: The
ICE_EXTRACTIONandREGOLITH_EXTRACTIONmodes currently create resources from nothing. They should consume a base resource (e.g., “Raw_Regolith”) to be more realistic.[ ] Implement Metal Production: Add a
METALtask and ISRU mode processingFeTiO3_kg(Ilmenite) to produceFe_kg,Ti_kg, andO2_kg.[ ] Add Dynamic Fleet Expansion: The sector should listen for
module_completedevents forISRU_Robot_EQto dynamically add new robots to its fleet.[ ] Consider Robot Specialization: Task assignment now splits robots proportionally by deficiency and matches ISRU mode capability, but doesn’t yet account for per-robot efficiency differences when choosing which capable robot to assign.