### Execute Simulations via Command-Line Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Provides examples of running dispatching experiments using the main.py CLI, including options for dataset selection, dispatching algorithms, and experiment logging. ```bash python main.py --dataset SMT2020_HVLM --days 365 --dispatcher fifo --seed 0 python main.py --dataset SMT2020_LVHM --days 365 --dispatcher cr --seed 42 --wandb ``` -------------------------------- ### GET /simulation/gym/environment Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Initializes the OpenAI Gym-compatible environment for training Reinforcement Learning agents on fab scheduling scenarios. ```APIDOC ## GET /simulation/gym/environment ### Description Retrieves or initializes the DynamicSCFabSimulationEnvironment for RL training, allowing observation of state components like batch fullness and critical ratios. ### Method GET ### Endpoint /simulation/gym/environment ### Parameters #### Query Parameters - **state_components** (list) - Required - List of observation features to include in the environment state. ### Request Example { "state_components": ["BATCH_FULLNESS", "MAX_CR", "MAX_WAIT_TIME"] } ### Response #### Success Response (200) - **environment_id** (string) - Unique ID for the initialized gym environment. #### Response Example { "environment_id": "gym_env_001" } ``` -------------------------------- ### Run PySCFabSim Simulation Instance Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt This snippet demonstrates how to initialize and run the core simulation engine (`FileInstance`). It loads dataset files, configures simulation parameters like runtime and dispatching mode, sets a random seed for reproducibility, and iteratively advances the simulation until completion. It also includes a basic example of dispatching lots to machines. ```python from simulation.file_instance import FileInstance from simulation.read import read_all from simulation.plugins.cost_plugin import CostPlugin from simulation.randomizer import Randomizer # Load dataset files files = read_all('datasets/SMT2020_HVLM') # Configure simulation parameters run_to = 3600 * 24 * 365 # Simulate for 365 days (in seconds) lot_for_machine = True # Use lot-for-machine dispatching mode plugins = [CostPlugin()] # Track costs during simulation # Set random seed for reproducibility Randomizer().random.seed(42) # Create the simulation instance instance = FileInstance(files, run_to, lot_for_machine, plugins) # Run simulation until completion while not instance.done: done = instance.next_decision_point() instance.print_progress_in_days() if done or instance.current_time > run_to: break # Dispatch lots to machines (custom logic here) for machine in instance.usable_machines: if machine.waiting_lots: lots = [machine.waiting_lots[0]] instance.dispatch(machine, lots) break # Finalize and collect statistics instance.finalize() print(f"Simulation completed: {instance.current_time_days:.1f} days") print(f"Lots completed: {len(instance.done_lots)}") ``` -------------------------------- ### Install Project Requirements Source: https://github.com/prosysscience/pyscfabsim-release/blob/master/README.md Installs all necessary Python packages for the project using pip. It is recommended to run this command within a new virtual environment to avoid dependency conflicts. ```shell pip install -r requirements.txt ``` -------------------------------- ### Implement Custom Metrics Plugin (Python) Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Provides an example of how to extend the simulation environment's functionality by implementing a custom plugin. The `CustomMetricsPlugin` class inherits from `IPlugin` and overrides methods like `on_sim_init`, `on_dispatch`, and `on_lot_done` to track specific simulation metrics. ```Python from simulation.plugins.interface import IPlugin class CustomMetricsPlugin(IPlugin): """Track custom metrics during simulation.""" def __init__(self): self.dispatch_count = 0 self.late_lots = 0 self.total_tardiness = 0 self.setup_changes = 0 def on_sim_init(self, instance): """Called when simulation initializes.""" print(f"Simulation starting with {len(instance.machines)} machines") def on_lots_release(self, instance, lots): """Called when lots are released into the fab.""" for lot in lots: print(f"Released: {lot.name} (deadline: {lot.deadline_at/3600:.1f}h)") def on_dispatch(self, instance, machine, lots, machine_end_time, lot_end_time): """Called when lots are dispatched to a machine.""" self.dispatch_count += 1 if machine.last_setup != machine.current_setup: self.setup_changes += 1 def on_lot_done(self, instance, lot): """Called when a lot completes all processing.""" if lot.done_at > lot.deadline_at: self.late_lots += 1 self.total_tardiness += lot.done_at - lot.deadline_at def on_sim_done(self, instance): """Called when simulation completes.""" print(f"\n=== Simulation Complete ===") print(f"Total dispatches: {self.dispatch_count}") print(f"Setup changes: {self.setup_changes}") print(f"Late lots: {self.late_lots}") print(f"Total tardiness: {self.total_tardiness/3600:.1f} hours") def get_output_name(self): return 'custom_metrics' def get_output_value(self): return { 'dispatches': self.dispatch_count, 'late_lots': self.late_lots, 'tardiness_hours': self.total_tardiness / 3600 } ``` -------------------------------- ### Access Machine Properties in PySCFabSim Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt This code snippet shows how to iterate through the machines within a running simulation instance and access their various properties. It displays information such as machine index, family, group, setup and processing times, current setup status, utilization, and the number of lots waiting for processing. ```python from simulation.classes import Machine # Machines are typically created from dataset files # Access machine properties during simulation: for machine in instance.machines: print(f"Machine {machine.idx}") print(f" Family: {machine.family}") print(f" Group: {machine.group}") print(f" Load time: {machine.load_time}s") print(f" Unload time: {machine.unload_time}s") print(f" Current setup: {machine.current_setup}") print(f" Utilized time: {machine.utilized_time}s") print(f" Setup time: {machine.setuped_time}s") print(f" Waiting lots: {len(machine.waiting_lots)}") # Check if machine requires minimum runs before setup change if machine.min_runs_left is not None: print(f" Min runs left: {machine.min_runs_left}") ``` -------------------------------- ### Draw Timeline Chart with Google Charts (JavaScript) Source: https://github.com/prosysscience/pyscfabsim-release/blob/master/simulation/plugins/visualization_template.html This snippet demonstrates how to draw a timeline chart using the Google Charts library in JavaScript. It initializes the chart, sets up the data table with columns for position, name, style, start date, and end date, and configures chart options such as row grouping. The chart is then rendered in a specified HTML container. ```javascript google.charts.load("current", {packages: ["timeline"]}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var container = document.getElementById('example3.1'); var chart = new google.visualization.Timeline(container); var dataTable = new google.visualization.DataTable(); dataTable.addColumn({type: 'string', id: 'Position'}); dataTable.addColumn({type: 'string', id: 'Name'}); dataTable.addColumn({type: 'string', role: 'style'}); dataTable.addColumn({type: 'date', id: 'Start'}); dataTable.addColumn({type: 'date', id: 'End'}); dataTable.addRows([["DATA"]]); //dataTable.addRows([['_', '_', 'fill-color: #ffffff', new Date(1514772800000), new Date(1514772800000)]]); // dataTable.addRows([['_', '_', 'fill-color: #ffffff', new Date(1514899015000), new Date(1514899015000)]]); var options = { colors: [["COLORS"]], timeline: { groupByRowLabel: true, }, }; chart.draw(dataTable); } ``` -------------------------------- ### Create and Run a Basic Fab Simulation Environment (Python) Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Demonstrates how to initialize a `DynamicSCFabSimulationEnvironment` with specific parameters and run a single simulation episode using random actions. It shows how to access observation and action spaces and print simulation results. ```Python from simulation.gym.environment import DynamicSCFabSimulationEnvironment from simulation.gym.action import E # Create environment env = DynamicSCFabSimulationEnvironment( num_actions=8, # Max action choices per step active_station_group='[LITHO]', # Focus on lithography stations days=30, # Simulation duration dataset='SMT2020_HVLM', # High-Volume Low-Mix dataset dispatcher='fifo', # Fallback dispatcher seed=42, # Random seed max_steps=10000, # Episode length limit reward_type=1, # Reward function (1=throughput) action=E.A.CHOOSE_LOT_FOR_FREE_MACHINE, state_components=state_components ) # Standard Gym interface observation = env.reset() print(f"Observation space: {env.observation_space}") print(f"Action space: {env.action_space}") # Run one episode total_reward = 0 done = False while not done: action = env.action_space.sample() # Random action observation, reward, done, info = env.step(action) total_reward += reward print(f"Episode finished. Total reward: {total_reward}") print(f"Lots completed: {len(env.instance.done_lots)}") ``` -------------------------------- ### Configure Simulation with Plugins Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Demonstrates how to initialize a simulation instance using the FileInstance class, incorporating custom plugins like the CostPlugin to track performance metrics such as tardiness and completion rates. ```python from simulation.file_instance import FileInstance from simulation.read import read_all from simulation.plugins.cost_plugin import CostPlugin files = read_all('datasets/SMT2020_HVLM') cost_plugin = CostPlugin() instance = FileInstance(files, 3600*24*365, True, [cost_plugin]) instance.finalize() print(f"Total cost: {cost_plugin.cost}") ``` -------------------------------- ### Core Simulation Engine: Instance Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Demonstrates how to initialize and run the main simulation engine using the Instance class. ```APIDOC ## Instance - Core Simulation Engine ### Description The `Instance` class represents the main simulation engine that manages the discrete event simulation, coordinating machines, lots, routes, and dispatching decisions. ### Method ```python from simulation.file_instance import FileInstance from simulation.read import read_all from simulation.plugins.cost_plugin import CostPlugin from simulation.randomizer import Randomizer # Load dataset files files = read_all('datasets/SMT2020_HVLM') # Configure simulation parameters run_to = 3600 * 24 * 365 # Simulate for 365 days (in seconds) lot_for_machine = True # Use lot-for-machine dispatching mode plugins = [CostPlugin()] # Track costs during simulation # Set random seed for reproducibility Randomizer().random.seed(42) # Create the simulation instance instance = FileInstance(files, run_to, lot_for_machine, plugins) # Run simulation until completion while not instance.done: done = instance.next_decision_point() instance.print_progress_in_days() if done or instance.current_time > run_to: break # Dispatch lots to machines (custom logic here) for machine in instance.usable_machines: if machine.waiting_lots: lots = [machine.waiting_lots[0]] instance.dispatch(machine, lots) break # Finalize and collect statistics instance.finalize() print(f"Simulation completed: {instance.current_time_days:.1f} days") print(f"Lots completed: {len(instance.done_lots)}") ``` ### Parameters No direct parameters for initialization in this example, configuration is done via variables before instantiation. ### Request Example N/A (This is a Python class initialization and execution) ### Response N/A (This is a Python class initialization and execution, results are printed to console or collected via plugins) ``` -------------------------------- ### Initialize RL Simulation Environment Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Sets up the DynamicSCFabSimulationEnvironment using specific state observation components for training reinforcement learning agents. ```python from simulation.gym.environment import DynamicSCFabSimulationEnvironment from simulation.gym.E import E state_components = ( E.A.L4M.S.OPERATION_TYPE.NO_LOTS_PER_BATCH, E.A.L4M.S.OPERATION_TYPE.CR.MAX, E.A.L4M.S.OPERATION_TYPE.FREE_SINCE.MAX, E.A.L4M.S.OPERATION_TYPE.SETUP.MIN_RUNS_OK, E.A.L4M.S.OPERATION_TYPE.SETUP.NEEDED, E.A.L4M.S.OPERATION_TYPE.SETUP.LAST_SETUP_TIME, ) ``` -------------------------------- ### Load and Preprocess Datasets Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Explains how to load SMT2020 dataset files and apply preprocessing filters to simplify simulation scenarios by removing factors like breakdowns or rework loops. ```python from simulation.read import read_all from simulation.dataset_preprocess import RemoveBreakdowns, RemoveRework # Load with specific preprocessors preprocessors = [RemoveBreakdowns(), RemoveRework()] simplified_files = read_all('datasets/SMT2020_LVHM', preprocessors) # Or use environment variables for auto-application import os os.environ['NOBREAKDOWN'] = '1' files = read_all('datasets/SMT2020_HVLM') ``` -------------------------------- ### Train RL Agent with Stable Baselines3 (Python) Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Shows how to train a Proximal Policy Optimization (PPO) agent using the Stable Baselines3 library. It includes setting up training and evaluation environments, defining the PPO model, implementing checkpointing, and saving/loading the trained model. ```Python from stable_baselines3 import PPO from stable_baselines3.common.callbacks import CheckpointCallback from simulation.gym.environment import DynamicSCFabSimulationEnvironment from simulation.gym.sample_envs import DEMO_ENV_1 # Create training environment train_env = DynamicSCFabSimulationEnvironment( num_actions=8, active_station_group=None, # All stations days=60, dataset='SMT2020_HVLM', dispatcher='fifo', seed=0, max_steps=100000, reward_type=1, **DEMO_ENV_1 # Use predefined state components ) # Create evaluation environment eval_env = DynamicSCFabSimulationEnvironment( num_actions=8, active_station_group=None, days=60, dataset='SMT2020_HVLM', dispatcher='fifo', seed=777, max_steps=10000, reward_type=1, **DEMO_ENV_1 ) # Initialize PPO model model = PPO( "MlpPolicy", train_env, verbose=1, learning_rate=3e-4, n_steps=2048, batch_size=64, n_epochs=10, ) # Train with checkpointing checkpoint_callback = CheckpointCallback( save_freq=10000, save_path='./checkpoints/', name_prefix='ppo_fab' ) model.learn( total_timesteps=100000, callback=checkpoint_callback, eval_env=eval_env, eval_freq=20000, n_eval_episodes=1 ) # Save trained model model.save('ppo_fab_scheduler') # Load and use trained model model = PPO.load('ppo_fab_scheduler') obs = eval_env.reset() for _ in range(1000): action, _ = model.predict(obs, deterministic=True) obs, reward, done, info = eval_env.step(action) if done: break ``` -------------------------------- ### Configure Built-in Dispatching Rules Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Demonstrates how to retrieve and apply built-in dispatchers like FIFO or Critical Ratio to select lots for machine processing. ```python from simulation.dispatching.dispatcher import Dispatchers, dispatcher_map from simulation.greedy import get_lots_to_dispatch_by_machine dispatcher = dispatcher_map['cr'] machine, lots = get_lots_to_dispatch_by_machine(instance, ptuple_fcn=dispatcher, machine=None) if lots is not None: instance.dispatch(machine, lots) lot = instance.active_lots[0] ptuple = Dispatchers.cr_ptuple_for_lot(lot, time=instance.current_time, machine=machine, setups=instance.setups) print(f"Priority tuple: {ptuple}") ``` -------------------------------- ### Reproduce Dispatcher Experiments Source: https://github.com/prosysscience/pyscfabsim-release/blob/master/README.md Executes shell scripts to reproduce experiments related to FIFO and CR dispatching strategies. This script automates the process of running simulations and collecting results for analysis. ```shell ./reproduce_dispatcher_experiments.sh ``` -------------------------------- ### Manufacturing Process Flow: Route and Step Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Overview of the Route and Step classes, defining the sequence of operations for a lot. ```APIDOC ## Route and Step - Manufacturing Process Flow ### Description The `Route` class defines the sequence of processing steps a lot must follow, with each `Step` specifying machine family, processing times, and batching rules. ### Method ```python from simulation.classes import FileRoute, Step # Route and Step objects are typically loaded from dataset files and associated with Lots. # Accessing them would be through a Lot object's route information or directly if loaded. # Example of accessing steps within a route (assuming 'lot' is an instance of Lot): if lot.route: print(f"Route for Lot {lot.idx}: {lot.route.name}") for step in lot.route.steps: print(f" Step: {step.step_name}") print(f" Machine Family: {step.family}") print(f" Processing Time: {step.process_time}s") print(f" Batch Min/Max: {step.batch_min}/{step.batch_max}") ``` ### Parameters Route and Step details are part of the loaded simulation data, accessed through Lot objects. ### Request Example N/A (Accessing data structures loaded from files) ### Response N/A (Output is printed to console via `print` statements) ``` -------------------------------- ### Analyze and Export Statistics Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Shows how to generate and export detailed simulation statistics, including per-lot and per-machine performance metrics, using the print_statistics utility. ```python from simulation.stats import print_statistics print_statistics( instance, days=365, dataset='SMT2020_HVLM', disp='cr', method='experiment_1', dir='results' ) ``` -------------------------------- ### Route and Step Definitions in PySCFabSim Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt This section describes the `Route` and `Step` classes in PySCFabSim, which define the manufacturing process flow for lots. A `Route` is a sequence of `Step` objects, where each `Step` specifies details like the required machine family, processing times, and batching rules. ```python from simulation.classes import FileRoute, Step # Routes and Steps are typically loaded from dataset files and used internally by the simulation instance. ``` -------------------------------- ### Access Lot Properties in PySCFabSim Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt This snippet illustrates how to access and display properties of individual lots within the simulation. It covers lot identification, part name, priority, piece count, release time, deadline, remaining processing steps, and estimated remaining time. It also shows how to calculate the Critical Ratio (CR) and access details about the lot's current processing step. ```python from simulation.classes import Lot # Access lot properties during simulation for lot in instance.active_lots: print(f"Lot {lot.idx}: {lot.name}") print(f" Part: {lot.part_name}") print(f" Priority: {lot.priority}") print(f" Pieces: {lot.pieces}") print(f" Release time: {lot.release_at}s") print(f" Deadline: {lot.deadline_at}s") print(f" Remaining steps: {len(lot.remaining_steps)}") print(f" Remaining time: {lot.remaining_time}s") # Calculate Critical Ratio (CR) cr = lot.cr(instance.current_time) print(f" Critical Ratio: {cr:.3f}") # Check current step if lot.actual_step: print(f" Current step: {lot.actual_step.step_name}") print(f" Required family: {lot.actual_step.family}") print(f" Batch min/max: {lot.actual_step.batch_min}/{lot.actual_step.batch_max}") ``` -------------------------------- ### Inspect Manufacturing Routes Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Iterates through defined routes in a simulation instance to display step details, including machine family, processing times, and batch constraints. ```python for route_name, route in instance.routes.items(): print(f"Route: {route_name}") print(f" Total steps: {len(route.steps)}") for i, step in enumerate(route.steps): print(f" Step {i}: {step.step_name}") print(f" Machine family: {step.family}") print(f" Processing time avg: {step.processing_time.avg():.1f}s") print(f" Setup required: {step.setup_needed or 'None'}") print(f" Batch size: {step.batch_min}-{step.batch_max}") print(f" Sampling %: {step.sampling_percent}") print(f" Rework %: {step.rework_percent}") ``` -------------------------------- ### POST /simulation/dispatch Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Dispatches lots to machines using specific priority rules such as FIFO, Critical Ratio (CR), or custom logic. ```APIDOC ## POST /simulation/dispatch ### Description Dispatches a list of lots to a machine based on a provided priority tuple function (dispatcher). ### Method POST ### Endpoint /simulation/dispatch ### Parameters #### Request Body - **dispatcher_key** (string) - Required - The key of the dispatcher to use (e.g., 'fifo', 'cr', 'srpt'). - **machine_id** (string) - Optional - Specific machine identifier. If null, selects any usable machine. ### Request Example { "dispatcher_key": "cr", "machine_id": null } ### Response #### Success Response (200) - **status** (string) - Success confirmation. - **dispatched_lots** (array) - List of lot IDs dispatched. #### Response Example { "status": "success", "dispatched_lots": ["lot_001", "lot_002"] } ``` -------------------------------- ### Manufacturing Equipment: Machine Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Details on accessing and utilizing properties of the Machine class, representing fabrication equipment. ```APIDOC ## Machine - Manufacturing Equipment ### Description The `Machine` class represents processing equipment in the fab, including properties for setup times, maintenance schedules, and utilization tracking. ### Method ```python from simulation.classes import Machine # Machines are typically created from dataset files # Access machine properties during simulation: for machine in instance.machines: print(f"Machine {machine.idx}") print(f" Family: {machine.family}") print(f" Group: {machine.group}") print(f" Load time: {machine.load_time}s") print(f" Unload time: {machine.unload_time}s") print(f" Current setup: {machine.current_setup}") print(f" Utilized time: {machine.utilized_time}s") print(f" Setup time: {machine.setuped_time}s") print(f" Waiting lots: {len(machine.waiting_lots)}") # Check if machine requires minimum runs before setup change if machine.min_runs_left is not None: print(f" Min runs left: {machine.min_runs_left}") ``` ### Parameters Access to machine properties is done via the `instance.machines` list. ### Request Example N/A (Accessing properties of existing machine objects) ### Response N/A (Output is printed to console via `print` statements) ``` -------------------------------- ### Implement Custom Dispatching Logic Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Defines a custom Shortest Remaining Processing Time (SRPT) dispatcher by returning a priority tuple. This function is registered in the dispatcher map and used to sort waiting lots. ```python def custom_shortest_remaining_time(lot, time, machine=None, setups=None): if machine is not None: setup_time = 0 new_setup = lot.actual_step.setup_needed if new_setup != '' and machine.current_setup != new_setup: if (machine.current_setup, new_setup) in setups: setup_time = setups[(machine.current_setup, new_setup)] return (0 if machine.min_runs_left is None or machine.min_runs_setup == new_setup else 1, 0 if lot.cqt_waiting is not None else 1, setup_time, lot.remaining_time, -lot.priority) else: return (lot.remaining_time, -lot.priority) dispatcher_map['srpt'] = custom_shortest_remaining_time ``` -------------------------------- ### Production Jobs: Lot Source: https://context7.com/prosysscience/pyscfabsim-release/llms.txt Information on the Lot class, representing production jobs with their attributes and processing status. ```APIDOC ## Lot - Production Jobs ### Description The `Lot` class represents a batch of wafers moving through the manufacturing process with defined routes, priorities, and deadlines. ### Method ```python from simulation.classes import Lot # Access lot properties during simulation for lot in instance.active_lots: print(f"Lot {lot.idx}: {lot.name}") print(f" Part: {lot.part_name}") print(f" Priority: {lot.priority}") print(f" Pieces: {lot.pieces}") print(f" Release time: {lot.release_at}s") print(f" Deadline: {lot.deadline_at}s") print(f" Remaining steps: {len(lot.remaining_steps)}") print(f" Remaining time: {lot.remaining_time}s") # Calculate Critical Ratio (CR) cr = lot.cr(instance.current_time) print(f" Critical Ratio: {cr:.3f}") # Check current step if lot.actual_step: print(f" Current step: {lot.actual_step.step_name}") print(f" Required family: {lot.actual_step.family}") print(f" Batch min/max: {lot.actual_step.batch_min}/{lot.actual_step.batch_max}") ``` ### Parameters Access to lot properties is done via the `instance.active_lots` list. ### Request Example N/A (Accessing properties of existing lot objects) ### Response N/A (Output is printed to console via `print` statements) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.