Skip to main content

State Machine Serialization Language

Project description

SMSL: State Machine Serialization Language

MIT License Version

SMSL is a data language designed specifically for serializing finite state machines. It provides a clean and intuitive syntax for defining state machines, with support for multiple common data formats.

Features

  • State Machine Serialization: Read and serialize finite state machines from/to string-based data formats
  • Multiple Format Support: Works with SMSL, JSON, and YAML formats
  • Graph Integration: Built-in integration with graph data structures, enabling any graph algorithm for your needs
  • Visualization Tools: Visualize your state machines using NetworkX and matplotlib
  • Path Finding: Find shortest paths between states in your state machine

Installation

pip install pysmsl

Usage

Basic Usage

import smsl

# Load a state machine from a file
sm = smsl.smslStateMachine('examples/hanoi.json')

# Access the state machine
state_branch = sm.state_machine[0]

# Find the shortest path between two states
from smsl_state import smslState
path = state_branch.shortest_path(
    smslState('State_aaa'),
    smslState('State_ccc')
)

# Get the operations (edges) along that path
edge_path = state_branch.shortest_edge_path(
    smslState('State_aaa'),
    smslState('State_ccc')
)

# Visualize the state machine
state_branch.plot_sb()

State Machine Definition Formats

SMSL Format

// SMSL format example
{
    # NAME: SB1
    # INITIAL: State000
    # NUM_FACTS: 3
    # SUB_SBS: (SB2: 0)

    State000: [Operation000 -> State100],

    State100: [
        Operation100A -> State110,
        Operation100B -> State111
    ],
        
    State110: [
        Operation110A -> State100,
        Operation110B -> State111
    ],

    State111: [ ]
}

JSON Format

{
    "SB1": {
        "HEADER": {
            "INITIAL": "State000",
            "NUM_FACTS": 3,
            "SUB_SBS": {
                "SB2": 0 
            }
        },
        "State000": {
            "Operation000": "State100"
        },
        "State100": {
            "Operation100A": "State110",
            "Operation100B": "State111"
        },
        "State110": {
            "Operation110A": "State100",
            "Operation110B": "State111"
        },
        "State111": { }
    }
}

YAML Format

SB1: [
  HEADER: [
    INITIAL: State000,
    NUM_FACTS: 3,
    SUB_SBS: [
      SB2: 0
    ]
  ],
  State000: [
    Operation000: State100
  ],
  State100: [
    Operation100A: State110,
    Operation100B: State111
  ],
  State110: [
    Operation110A: State100,
    Operation110B: State111
  ],
  State111: [ ]
]

Examples

The repository includes several examples:

  • examples/example.smsl, examples/example.json, examples/example.yaml: Simple state machine examples in different formats
  • examples/hanoi.json: A state machine for solving the Tower of Hanoi puzzle

Tutorials

Tower of Hanoi

The repository includes a complete example of using SMSL to solve the Tower of Hanoi puzzle:

  • tutorials/hanoi/hanoi_vtk_sim/: A VTK simulation of the Tower of Hanoi
  • tutorials/hanoi/hanoi_robot/: A robot implementation for playing Tower of Hanoi

To run the VTK simulation:

cd tutorials/hanoi/hanoi_vtk_sim
python hanoi_vtk_sim.py

Design Philosophy

SMSL is designed with the following goals in mind:

  1. Simplicity: Easy to read and write state machine definitions
  2. Flexibility: Support for multiple data formats (SMSL, JSON, YAML)
  3. Extensibility: Integration with graph algorithms for advanced state machine analysis
  4. Visualization: Tools for visualizing and understanding state machines

Dependencies

  • Python 3.6+
  • networkx
  • matplotlib
  • pyyaml

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use SMSL in your research, please consider citing the following papers:

@article{liu2024roadmap,
  title={A Roadmap Towards Automated and Regulated Robotic Systems},
  author={Liu, Yihao and Armand, Mehran},
  journal={arXiv preprint arXiv:2403.14049},
  year={2024}
}

@article{liu2023toward,
  title={Toward Process Controlled Medical Robotic System},
  author={Liu, Yihao and Kheradmand, Amir and Armand, Mehran},
  journal={arXiv preprint arXiv:2308.05809},
  year={2023}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysmsl-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysmsl-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pysmsl-0.1.0.tar.gz.

File metadata

  • Download URL: pysmsl-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for pysmsl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 248bdcdcab459b4a0e0da671253a64c3df816f3db6f099e5c2040faf8908fef4
MD5 747aed9df46a3355df3be042214e5f0d
BLAKE2b-256 990fbbad307c3df59d24dde70b7ed9a545ef0228c5fefd77b7390badb18b85a8

See more details on using hashes here.

File details

Details for the file pysmsl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pysmsl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for pysmsl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f0a8446b212435b20cdc28f2431234dbd0cec2def76cca073e3507474a547c1
MD5 0cf1f3af2c7c008e091f995ffe5095ae
BLAKE2b-256 7226f18a1f092148090b943599145eda8017ac3e9f688bbfed6967f1bfd5ba6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page