Skip to main content

FiKnight

FiKnight is a simple implementation of a Finite State Machine implemented in Python. There are five essential moving parts, each of these is its own object:

  1. Machine
  2. State
  3. Event
  4. Transition Table
  5. Display

The chain of belonging is as follows: Machine > State > Transition Table > Event --> All events are designed to be triggered from the display and also change items on the display.

Example usage:

##Imports
from fiknight.fsm.core import *
from fiknight.fsm.common.events import *

##Instantiate the machine
fsm = Machine(name='Prototype')

##Define the states:
s1 = State(name="Stage_1", machine=fsm)
s2 = State(name="Stage_2", machine=fsm)
s3 = State(name="Stage_3", machine=fsm)

##Define the events that carry the transitions from common events:
s1.addEvent(clickEvent(name="clickEvent", destinations=s2))
s2.addEvent(clickEvent(name="clickEvent", destinations=s3))
s3.addEvent(clickEvent(name="clickEvent", destinations=s1))

##Compile the states into the machine:
fsm.addState(s1) #the first state that you add is the initial state.
fsm.addState(s2)
fsm.addState(s3)

##Execute each event
for i in range(3):
    fsm.current_state.resolveEventTransition("clickEvent")
    print(fsm.current_state.name)
    print(fsm.history)

At any point, you can view the transition tables with some rudimentary print modification:

##Walk through the machine:
for ev in fsm.state_stack:
    ev.transitions.showTable()

Instead of creating a machine piece-by-piece, some boilerplates have been built in:

##Imports
from fiknight.fsm.core import *
from fiknight.fsm.common.events import *
from fiknight.fsm.common.generator import *

##Build a three cycle machine.
fsm = sequentialMachine("Prototype", n_states=3)

##Walk through the machine.
for i in range(3):
    fsm.current_state.resolveEventTransition("baseTransition")
    print(fsm.current_state.name)
    print(fsm.history)

Instead of creating a machine piece-by-piece, some boilerplates have been built in:

##Imports
from fiknight.fsm.core import *
from fiknight.fsm.common.events import *
from fiknight.fsm.common.generator import *

##Build a three cycle machine.
fsm = sequentialMachine("Prototype", n_states=3)

##Walk through the machine.
for i in range(3):
    fsm.current_state.resolveEventTransition("baseTransition")
    print(fsm.current_state.name)
    print(fsm.history)

A state machine can also be connected and translated to NetworkX easily:

##Imports
from fiknight.fsm.core import *
from fiknight.fsm.common.events import *
from fiknight.fsm.common.generator import *
from fiknight.fsm.export.networkx import *

##Build a three cycle machine.
fsm = sequentialMachine("Prototype", n_states=3)

##Walk through the machine.
for i in range(3):
    fsm.current_state.resolveEventTransition("baseTransition")
    print(fsm.current_state.name)
    print(fsm.history)

##Get a nx object for algorithms or inference:
toNetworkx(fsm)
##Just access the nx graphing mechanisms:
getGraph(machine=fsm, output="../test.png")

Support for saving a machine forthcoming

Support for GUI creation of events forthcoming

Release files for fiknight 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fiknight 0.1.0
File Interpreter ABI Platform
fiknight-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / fiknight-0.1.0-py3-none-any.whl

Download URL fiknight-0.1.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef5019c00da1d2f22888ac867e70f4c24c882b650f709b373def01686b90af1d
BLAKE2b-256 checksum
How to use checksums
aaff4160b94693f9ebd23f3ecef4e9f27d6d90159b353311cf0fc9f7b1f7b554
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page