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.1.tar.gz (7.4 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.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysmsl-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 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.1.tar.gz
Algorithm Hash digest
SHA256 b4866de700c1153eb46289384fc49133988f3b1b0487bafae06aef5e996ff784
MD5 998ac78c1a15673115c016a371bededb
BLAKE2b-256 c65a7a8f7e8d9c4ecbba0d6cd22586fe4c0554e8542f843178ec5c7bcb2acefc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pysmsl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 246434b465680ff3f8621da3fba8c3396829001adce8da7f9dcdbdc45448c65a
MD5 80624f00810eece96cc17f397ccdca80
BLAKE2b-256 28b894e8e35941556e635a6b65119b0624dbd8c9bb924b30c694ad9794e330dc

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