Skip to content

optimaru.semiconductor_scheduling

Generated from the sources of optimaru/semiconductor_scheduling/ and the stubs of its compiled extension. The guide explains the model and the constraints in prose.

optimaru.semiconductor_scheduling

Semiconductor fab scheduling — Python wrapper of the C++ solver on the optimaru engine.

Lots follow re-entrant routes over alternative tools (batch tools included), with sequence-dependent setups, inter-tool transport, queue-time windows, maintenance windows, auxiliary resources and pinned operations. The search state is one machine choice and one priority rank per operation, folded into one assignment-shape decision value per operation row (rank * K + slot); the C++ serial schedule-generation decoder turns it into the schedule (assignments).

Score, at the default weights: hard = the sum of the 14 hard constraints, soft = preference + minimum batch fill + load imbalance + 10 x weighted tardiness + cycle time + makespan (see optimaru.semiconductor_scheduling.constraints; constraint_info() lists every default level and weight).

Basic usage::

import optimaru.semiconductor_scheduling as fab
from optimaru.semiconductor_scheduling.models import SemiconductorScheduleModel

problem = SemiconductorScheduleModel.model_validate(data)
problem = fab.solve(problem, time_limit_seconds=5.0, random_seed=42)   # a new, solved model
print(problem.score_hard, problem.score_soft, problem.makespan, problem.assignments[0])

solve and calculate_score take the Pydantic model or the engine object _core.SemiconductorSchedule (problem.to_core()). solve returns the solved problem: the engine object it was given, solved in place, or, for a model, a new model with the result (the model passed in is not changed). calculate_score returns the Score and writes the score fields into the model it is given.

optimaru.semiconductor_scheduling.models

AuxiliaryResourceModel

Bases: StrictModel

Reusable operator, reticle, fixture, or transport resource.

SemiconductorScheduleModel

Bases: StrictModel

Re-entrant semiconductor-fab lot and equipment scheduling contract.

to_core

to_core()

pydantic -> engine object (_core.SemiconductorSchedule): ids become indices; facts, pins, assignments (batch ids included) and warm_start are passed on. The totals and scores are not: the engine recomputes them. Times beyond the engine's int64 range raise ValueError; a derived time or cost that overflows int64 later raises OverflowError.

from_core classmethod

from_core(schedule) -> SemiconductorScheduleModel

engine object -> pydantic: the facts by their ids, the assignments (batch_id None or a string), makespan, totals and scores (None while the schedule is not scored) and warm_start.

SemiconductorScheduleRequest

Bases: SolveRequest

The semiconductor schedule with the settings of one solve (see SolveRequest for those).

with_initial_solution

with_initial_solution(problem, solution)

Return a copy of problem whose search starts from solution.

solution is a solved problem model or a dict of the same shape; assignments are matched by lot and operation id. Machine eligibility and duration are checked here, against every option of the operation. Anything solve returns passes, feasible or not. Everything else, such as overlaps or route order, stays a hard penalty that the seed may break.

The search state is a machine choice and a priority rank per operation, which the serial decoder turns into a schedule. The seed is converted to that state: the machine gives the choice, the order of the start times gives the rank. The decoder left-shifts operations and re-derives batches, so decoding a seed can give another schedule, worse as well as better, even when the seed came out of a solve.

Guaranteed for a complete seed, one that assigns every operation: solve scores the supplied assignments directly without decoding them, returns them unchanged, batch ids included, unless the search finds a strictly better schedule, and so never ends with a score worse than the seed's.

Not guaranteed: that the search stays close to the seed or can improve it. Every schedule it visits after the seed is decoded, and a seed the decoder cannot reproduce may have no accepted neighbour, in which case it comes back as supplied. A partial seed cannot be scored, so it is decoded from the start: it keeps its machines and relative order, the left-out operations rank last on their default machine, and all start times are recomputed.

parameter_uses

parameter_uses(problem: SemiconductorScheduleModel) -> list[ParameterUse]

The parameters problem sets away from their defaults that act only through a cost.

semiconductor_scheduling.solve refuses a selection that holds none of a parameter's costs (optimaru._constraint.require_costs); the table is in docs/use-cases/README.md ("Parameters and their costs"). What the decoder builds into every schedule (release times, downtime, capacities, batch families, setups, transport, minimum queue times, pins) is not here: it holds whatever the constraints are. Nor are a lot's priority and an option's preference_cost: the decoder's dispatch order and default machine read them, whatever the constraints.

solve_request

solve_request(request: SemiconductorScheduleRequest, *, constraints=None) -> SemiconductorScheduleModel

Solve a pydantic request and return the solved problem model.

This is solve(request.model_input, ...) with the request's settings as the keywords of the same names (see SolveRequest), and constraints the selection solve takes. The request is not changed.

optimaru.semiconductor_scheduling.constraints

Constraint assembly specs — an API for picking the cost function declaratively.

The default path (solve(problem)) scores all 20 constraints at their default weights. This module is the alternative path next to it: pick constraints, change weights, change levels, shape the cost, and pass the list to solve(problem, constraints=...) or calculate_score(problem, constraints=...). A constraint list reads one way: one class call per constraint::

import optimaru.semiconductor_scheduling as fab
from optimaru.semiconductor_scheduling.constraints import (
    MachineEligibilityCost, MakespanCost, WeightedTardinessCost, get_constraints,
)

problem = fab.solve(problem, constraints=get_constraints())                       # defaults as-is
problem = fab.solve(problem, constraints=[MachineEligibilityCost(), MakespanCost(),
                                          WeightedTardinessCost(weight=50)])      # picked

Only listed constraints are scored — leave one out and its term disappears from the score. (The module also carries ready-made default instances: makespan_cost is MakespanCost(), and so on.)

Every spec takes five knobs:

  • weight linear multiplier on the constraint cost. None = the component default (every constraint 1, WeightedTardinessCost 10); constraint_info() reports them. The problem carries no weights.
  • level None = the default level, otherwise Level.HARD or Level.SOFT (or the names "hard" and "soft"). This use case has no medium level: level="medium" raises ValueError.
  • exponent sign-preserving power shaping of the constraint's TOTAL raw cost: weight * total ** exponent (every constraint is global, so the total is shaped, not each item — a lot, a pair, a window).
  • offset (keyword) shifts that shaping of the total; 0.0 = none.
  • clip (keyword) True (the default) counts only what lies beyond the offset, max(0, total - offset) ** exponent; False shapes total - offset as it is, so a total below the offset — a raw 0 included — lowers the penalty. With an offset it is refused on hard (the 14 constraints that are hard by default, or a soft one moved to hard), because hard 0 must mean no violation.

The same constraint may be picked several times; each pick is scored on its own with its own knobs (its level included) and the picks add up. The makespan plus a steep penalty on every minute beyond 480::

problem = fab.solve(problem, constraints=[
    *(spec for spec in get_constraints() if spec.name != "makespan_cost"),
    MakespanCost(),
    MakespanCost(weight=100, offset=480),
])

fab.constraint_costs(problem, picks) keys the second pick "makespan_cost#2".

Names (name) are the C++ component names in snake_case (MachineEligibilityCost -> machine_eligibility_cost); check them with fab.list_constraints().

Constraint dataclass

Spec selecting one constraint: weight / level / shaping.

Subclasses set the ClassVars: name (the snake_case registry name the core reports in list_constraints(); required), label_en / label_ko (a short title) and description_en / description_ko (one or two sentences on what one unit of raw cost means). An intermediate base that should not need a name passes abstract=True::

class _RouteLimit(Constraint, abstract=True): ...

offset and clip are keyword-only, so the positional order stays weight, level, exponent followed by a subclass's domain parameters. A name must not contain #, which constraint_costs() keys repeated picks with ("<name>#<k>").

params

params() -> dict[str, Any]

The domain parameters: every dataclass field but the five knobs.

Level

Bases: StrEnum

The score level a constraint is charged on. Hard dominates medium, medium dominates soft.

Score

Bases: NamedTuple

Engine-level (hard, soft) from score(). Penalties, so <= 0 without rewards.

A domain with a medium level folds it the way its C++ Score adapter does (into soft, or below hard), so this compares directly with the engine.

MachineEligibilityCost dataclass

Bases: Constraint

Operations without an assignment on an eligible machine. Default: hard, weight 1.

LotRoutePrecedenceCost dataclass

Bases: Constraint

Route steps that start before their release or their previous step's end. Default: hard, weight 1.

MachineCapacityCost dataclass

Bases: Constraint

Overlapping processing time on unary tools. Default: hard, weight 1.

BatchCapacityCost dataclass

Bases: Constraint

Capacity-time above a batch tool's simultaneous lot limit. Default: hard, weight 1.

BatchFamilyConflictCost dataclass

Bases: Constraint

Overlap time of different recipe families on one batch tool. Default: hard, weight 1.

MissingSetupTimeCost dataclass

Bases: Constraint

Sequence-dependent setup time missing between consecutive runs. Default: hard, weight 1.

MachineUnavailabilityCost dataclass

Bases: Constraint

Processing time inside machine downtime windows. Default: hard, weight 1.

MaxQueueTimeCost dataclass

Bases: Constraint

Waiting time beyond a route step's maximum queue time. Default: hard, weight 1.

MinQueueTimeCost dataclass

Bases: Constraint

Minimum hold time missing between consecutive route steps. Default: hard, weight 1.

MissingTransportTimeCost dataclass

Bases: Constraint

Material-handling time missing between consecutive route steps. Default: hard, weight 1.

AuxiliaryResourceCapacityCost dataclass

Bases: Constraint

Concurrent use above an auxiliary resource's capacity. Default: hard, weight 1.

AuxiliaryResourceUnavailabilityCost dataclass

Bases: Constraint

Use of an auxiliary resource inside its unavailable windows. Default: hard, weight 1.

PinnedAssignmentsCost dataclass

Bases: Constraint

Frozen operations that moved off their pinned machine or time. Default: hard, weight 1.

MaxCycleTimeCost dataclass

Bases: Constraint

Lot cycle time beyond its maximum. Default: hard, weight 1.

MachinePreferenceCost dataclass

Bases: Constraint

Preference cost of the chosen equipment. Default: soft, weight 1.

MinBatchSizeCost dataclass

Bases: Constraint

Lots missing below a batch tool's preferred minimum run size. Default: soft, weight 1.

MachineLoadImbalanceCost dataclass

Bases: Constraint

Processing-load range between the tools of each equipment group. Default: soft, weight 1.

WeightedTardinessCost dataclass

Bases: Constraint

Lot tardiness multiplied by its priority. Default: soft, weight 10.

CycleTimeCost dataclass

Bases: Constraint

Elapsed time from lot release to completion. Default: soft, weight 1.

MakespanCost dataclass

Bases: Constraint

Completion time of the last lot. Default: soft, weight 1.

get_constraints

get_constraints(constraints: list[Constraint] | None = None) -> list[Constraint]

Return the cost function. Without arguments, all 20 default constraints.

When constraints is given, that list is used as-is — only the listed constraints are scored. Same contract as the C++ applyConstraints: an empty list (most likely a filter that came out empty) raises ValueError; a constraint named several times is scored once per pick, each with its own knobs.

score

score(costs: dict, constraints: list[Constraint] | None = None) -> Score

Apply specs to raw constraint costs and produce a score — pure Python.

costs is what fab.constraint_costs(problem) returns: per constraint its raw total (one element: every constraint is global), its default weight and level. Fetch it once and rescore with different weights without re-solving::

raw = fab.constraint_costs(problem)
score(raw)                                              # default set
score(raw, [MachineEligibilityCost(), WeightedTardinessCost(weight=50)])
score(raw, [MakespanCost(), MakespanCost(weight=100, offset=480)])

The arithmetic matches the engine: weight * shape(total, exponent, offset, clip) per constraint, hard contributions rounded per constraint (half away from zero). A second pick of a constraint reads the same raw total with its own knobs. Unknown names raise ValueError, and so does level="medium" (no medium level here).

optimaru.semiconductor_scheduling._core

Type stubs for optimaru.semiconductor_scheduling._core — the semiconductor fab C++ solver.

The schedule object holds the solution. Its search state is one assignment-shape decision value per operation row (rank * K + slot: a decode priority and a machine option), which the serial schedule-generation decoder turns into assignments. Facts are indices into the schedule's lists (machines, auxiliary resources, lots, a lot's operations).

Score (hard/soft, lexicographic), at the default weights: hard = -(the 14 hard constraints' raw costs), soft = -(preference + min batch size + load imbalance + 10 * weighted tardiness + cycle time + makespan). The weights are the C++ components' defaults (constraint_info()); the schedule carries none.

Score

(hard, soft), compared lexicographically; also iterable and indexable as a pair.

is_feasible

is_feasible() -> bool

True when hard >= 0: no hard constraint is violated.

TimeWindow

[start, end), end > start >= 0.

Operation

required_resources property

required_resources: list[int]

Indices into auxiliary_resources; a resource listed twice is used twice.

Assignment

One operation (lot index, route position) on a machine index, [start, end).

SemiconductorSchedule

Problem and solution in one object. The constructor validates (ValueError) like the Pydantic model. Facts are read-only copies; assignments may be replaced (validated; clears the score).

warm_start instance-attribute

warm_start: bool

Start the next solve from assignments; reset to False by the solve.

scored property

scored: bool

False until calculate_score or a solve set score / makespan / totals.

SolverConfig

spent_limit_seconds instance-attribute

spent_limit_seconds: float

Wall-clock budget (30 s); 0 returns the start as is.

step_count_limit instance-attribute

step_count_limit: int

0 = no limit.

parallel_solver_count instance-attribute

parallel_solver_count: int

Independent starts, one thread each (seed + i); the strictly best wins. The constraints path runs one start.

acceptor_type instance-attribute

acceptor_type: AcceptorType

SIMULATED_ANNEALING by default.

entity_tabu_size instance-attribute

entity_tabu_size: int

ENTITY_TABU: for how many steps a moved entity stays tabu (7 by default; >= 0).

simulated_annealing_starting_temperature instance-attribute

simulated_annealing_starting_temperature: tuple[int, float]

SIMULATED_ANNEALING's (hard, soft) starting temperature, cooling to 0 over the solve. (0, 0), the default, = auto: hard 0, soft = simulated_annealing_temperature_fraction x |start soft| (at least 1).

simulated_annealing_temperature_fraction instance-attribute

simulated_annealing_temperature_fraction: float

The auto temperature's fraction of the start's |soft| (0.01 by default; > 0).

great_deluge_water_level_step instance-attribute

great_deluge_water_level_step: tuple[int, float]

GREAT_DELUGE: how much the (hard, soft) water level, which starts at the start's score, rises per step. (0, 0), the default, leaves it there: only moves that keep the score at or above the start's are taken.

step_counting_hill_climbing_size instance-attribute

step_counting_hill_climbing_size: int

STEP_COUNTING_HILL_CLIMBING: the bar is reset to the current score every this many steps (400 by default; > 0).

record_to_record_start_gap instance-attribute

record_to_record_start_gap: float

RECORD_TO_RECORD_TRAVEL: the gap below the best score that is still accepted at the start of the solve, as a fraction of the start's |soft| (0.02 by default; >= 0).

record_to_record_end_gap instance-attribute

record_to_record_end_gap: float

RECORD_TO_RECORD_TRAVEL: the same gap at the end of the solve (0.0 by default; >= 0); the gap shrinks from the start gap to this one.

late_acceptance_size instance-attribute

late_acceptance_size: int

LATE_ACCEPTANCE: 0 = auto: clamp(16 * operation rows, 400, 3200).

swap_move_weight instance-attribute

swap_move_weight: float

The engine's whole-value swap; off (0) by default.

machine_move_probability instance-attribute

machine_move_probability: float

Share of change moves that switch a row's machine (the rest shift its priority).

priority_swap_moves instance-attribute

priority_swap_moves: bool

Swap the priorities of two operations (machines kept).

custom_move_probability instance-attribute

custom_move_probability: float

Gate on how often a step may draw the priority swap.

ruin_recreate instance-attribute

ruin_recreate: bool

Off: a recreate evaluates every value of every ruined row, each one a decode.

best_score_limit instance-attribute

best_score_limit: tuple[int, float]

(hard, soft): stop once bestScore >= this; (0, -inf) stops at the first feasible.

Solver

Simulated annealing over the decoded search state. Solves IN PLACE: assignments, score, makespan, totals; warm_start = False. If the solve raises (RuntimeError when the decoder gives up, OverflowError past int64), the schedule keeps its assignments and scores them as before.

solve_with_constraints

solve_with_constraints(schedule: SemiconductorSchedule, constraints: Iterable[Any] | None = ...) -> None

The same search scored by a caller-chosen constraint set (single start); the list replaces the defaults, None keeps them. A name may be picked several times: each pick is its own instance with its own knobs (its level included), and the instances add up. There is no medium level: level="medium" raises ValueError.

ConstraintInfo

Bases: NamedTuple

One constraint-catalog row, read off the C++ default assembly.

calculate_score

calculate_score(schedule: SemiconductorSchedule, constraints: Iterable[Any] | None = None) -> Score

Score schedule.assignments as given (None = the default constraints, else the picks, a name picked several times once per pick) and store score, makespan, total_weighted_tardiness and total_cycle_time.

list_constraints

list_constraints() -> list[str]

Constraint names scored by this domain (default assembly order, snake_case): the names optimaru.semiconductor_scheduling.constraints uses.

constraint_costs

constraint_costs(schedule: SemiconductorSchedule, constraints: Iterable[Any] | None = ...) -> dict[str, dict[str, Any]]

Raw cost of every constraint on schedule.assignments, before weight/exponent/offset/level: {key: {"costs": [total], "weight": float, "exponent": float, "offset": float, "clip": bool, "global": True, "level": "hard" | "soft", "reward": bool, "level_flippable": bool, "name": str, "label": str, "default_weight": float, "default_level": str}}, "level" being the level in effect (the pick's, or the default) and "hard" the same as level == "hard". Every constraint is global, so "costs" holds one element. None = the default constraints; a pick list (as for solve) scores exactly those picks, each entry carrying its pick's knobs, the k-th pick of a name keyed "#" from the second on. optimaru.semiconductor_scheduling.constraints.score() turns it into a score.

constraint_items

constraint_items(schedule: SemiconductorSchedule) -> dict[str, list[int]]

Per-item raw costs (one item per lot, route pair, machine, window, ...).

constraint_info

constraint_info() -> list[ConstraintInfo]

The constraint catalog, in list_constraints() order: the first 14 hard at weight 1, then machine_preference_cost, min_batch_size_cost, machine_load_imbalance_cost (soft, 1), weighted_tardiness_cost (soft, 10), cycle_time_cost and makespan_cost (soft, 1); all flippable, none a reward, all scored by default (default_enabled).

default_choices

default_choices(schedule: SemiconductorSchedule) -> list[int]

Per operation row, the option with the least (preference cost, duration).

seed_state

seed_state(schedule: SemiconductorSchedule, choices: list[int]) -> tuple[list[int], list[int]]

schedule.assignments as a (choices, ranks) state: a seeded row takes the LAST option with its machine and duration; ranks follow (unseeded last, seeded start, row).

decode

decode(schedule: SemiconductorSchedule, choices: list[int], ranks: list[int]) -> list[Assignment]

The serial schedule-generation decoder; choices are used modulo the option count.