jmyrberg / factory-simulator

Factory simulator written in Python using simpy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🏭 Factory Simulator

Factory floor simulator written in Python using simpy. The simulator can be used as-is for a simple OPC-UA demo server in a container, or as a basis for more complex real factory floor simulation. See example simulation output for a 7-day simulation here and here.

Simulator

I have no plans on creating a package out of this hobby project, but hopefully you find it useful ✌️

Installation

You have two options:

  • Run simulation as an OPC-UA server with limited customization possibilities - see instructions here.

  • Run within Python with full customization possibilities - clone and install dependencies as follows:

    git clone https://github.com/jmyrberg/factory-simulator && \
    cd factory-simulator && \
    pip install requirements.txt

    After this, see getting started.

Getting started

The default configuration in factory.yml will showcase a simple example to get you started:

import logging
import sys

from src.simulator.factory import Factory


logging.basicConfig(
    stream=sys.stdout,
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)-7s - %(message)s",
    datefmt="%H:%M:%S",
)
logger = logging.getLogger(__name__)


logger.info('Starting simulation')
factory = Factory.from_config('config/factory.yml')
factory.run(7)
factory.data_df
# factory.plot()  # Set monitor=-1 in config for this to be meaningful

Please also see main.py and factory-simulator -notebook for reference.

It is recommended to start with this basic config and work your way towards your end goal from there. Depending on your goal, you may need to modify parts of the code itself, as the YAML-configuration has only limited number of settings that can be changed.

Architecture

The following describes the main components and states of a factory.

  graph TD;
    Container---Material
    Container---Consumable
    Machine---Schedule
    Schedule-- Switches -->Program
    Machine---Container
    FailureProcess(Failure process)-->Machine
    Filling(Filling process)-->Container
    Maintenance-->Machine
    Program---BOM
    Production-- Runs -->Program
    Material-- Input -->BOM
    Consumable-- Input -->BOM
    BOM-- Output -->Product
    Product-->ProductContainer(Product container)
    Work-- Operates -->Machine
    subgraph MachineStates
      Machine---Off
      Machine---On
      Machine---Error
      Machine---Production
    end
    subgraph OperatorStates
      Operator---Home
      Operator---Work
      Operator---Lunch
    end
    Sensors
    Collectors---Exporters

    click Machine "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/machine.py"
    click Container "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/container.py"
    click Consumable "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/consumable.py"
    click Material "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/material.py"
    click Product "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/product.py"
    click Schedule "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/schedules.py"
    click Program "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/program.py"
    click BOM "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/bom.py"
    click Operator "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/operator.py"
    click Sensors "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/sensors.py"
    click Exporters "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/exporters.py"
    click Filling "https://www.github.com/jmyrberg/factory-simulator/blob/master/src/simulator/actions.py"

Components:

  • Machines produce Products from discrete Materials and continuous Consumables as defined by Bill of Materials (BOM)
  • Operators may be at home, work or having lunch, and are responsible for operating machines and fixing simple errors
  • Containers store all materials, consumables and end products
  • Schedules define the production programs that are run and raw material procurement
  • Maintenance team fix more challenging machine errors
  • Sensors measure quantities or states from processes
  • Collectors define data to collect from the simulation, whereas Exporters write that data for later use

Other noteworthy features and processes:

  • Machine may heat up too much and parts may break, causing the machine to go in error state
  • Machine is maintained based on a schedule
  • Different programs may produce different products and consume different (amounts of) materials and consumables, and they may have different temperature profiles
  • Raw material and consumable procurement may fail, and they have quality that affects end product quality
  • Randomization is implemented by default in many operations and can be toggled on or off
  • Collector enables very flexible automatic data collection from Python object attributes

Jesse Myrberg (jesse.myrberg@gmail.com)

About

Factory simulator written in Python using simpy


Languages

Language:Python 98.8%Language:Jupyter Notebook 0.9%Language:Shell 0.2%Language:Dockerfile 0.2%