Git Product home page Git Product logo

visual-automata's Introduction

Hi, I'm Lewi Uberg ๐Ÿ‘‹

Stars Badge

I'm a husband, father of three boys, a former design egineer, and a final year data science student, currently working as a full-stack developer at Puzzel in Arendal, Norway.

  • Iโ€™m currently learning C# and JavaScript.
  • I'm a huge fan of the combination of pyenv, poetry, and zsh-autoswitch-virtualenv when I work on a project. The more I can control from pyptoject.tomlin my project the better.
  • A portfolio of some of my projects are available at https://uberg.me/portfolio/
  • I regularly write articles on https://uberg.me/posts/
  • Fun fact: I love woodworking and like to spend my free time in my workshop.

Connect with me:

uberg.me lewiuberg | LinkedIn lewiuberg | Medium lewiuberg | PyPI lewiuberg | Kaggle lewiuberg | Instagram lewiuberg | StackOverflow lewiuberg | HackerRank lewiuberg | RSS

Tools & Languages:



Stats:

lewiuberg

Projects:

Mine Contributions

Blogs posts:

visual-automata's People

Contributors

lewiuberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

visual-automata's Issues

VisualDFA constructor implicitly checks wrapped automaton cardinality

The VisualDFA constructor checks the dfa parameter using

This checks if dfa is truthy. Since the DFA class defines a __len__ method (and no __bool__), is is truthy iff len(dfa) != 0. Unfortunately, the length checks the dfa's cardinality, i.e., the size if the input language. For infinite-language DFAs, an exception is then raised. As a result, infinite DFAs cannot be visualized.

This could be fixed by testing if dfa is None. VisualNFA is not affected since NFA does not define a __len__ method at the moment, but would fail if a similar method would be added to NFA.

MRE

Using most recent versions:

  • automata-lib 7.0.1
  • visual_automata 1.1.1
from automata.fa.dfa import DFA
from visual_automata.fa.dfa import VisualDFA

dfa = DFA(states={"q0"}, input_symbols={"i0"}, transitions={"q0": {"i0": "q0"}}, initial_state="q0",
          final_states={"q0"})
VisualDFA(dfa).show_diagram(view=True)

Expected Behavior

The automaton is shown.

Actual Behavior

Traceback (most recent call last):
  File "/path/to/scratch_1.py", line 6, in <module>
    VisualDFA(dfa).show_diagram(view=True)
  File "/path/to/site-packages/visual_automata/fa/dfa.py", line 34, in __init__
    if dfa:
  File "/path/to/site-packages/automata/fa/dfa.py", line 160, in __len__
    return self.cardinality()
  File "/path/to/site-packages/automata/fa/dfa.py", line 792, in cardinality
    raise exceptions.InfiniteLanguageException("The language represented by the DFA is infinite.")
automata.base.exceptions.InfiniteLanguageException: The language represented by the DFA is infinite.

Workaround

Manually copying the automaton works:

VisualDFA(states=dfa.states, input_symbols=dfa.input_symbols, transitions=dfa.transitions,
          initial_state=dfa.initial_state, final_states=dfa.final_states).show_diagram(view=True)

FrozenNFA constructor attempts to call deepcopy on frozendicts

The VisualNFA constructor attempts to create a deep copy of the passed nfa, especially the transitions dictionary:

all_transitions = all_transitions.deepcopy()

The deepcopy method is monkeypatched onto dict via curse:

curse(dict, "deepcopy", deepcopy)

However, automata-lib 7.0.1 returns a frozendict from the frozendict package instead, so the method call fails. It is not clear if copying the frozendict is at all necessary; deepcopy returns the object as-is.

MRE

Using most recent versions:

  • automata-lib 7.0.1
  • visual_automata 1.1.1
from automata.fa.nfa import NFA
from visual_automata.fa.nfa import VisualNFA

nfa = NFA(states={"q0"}, input_symbols={"i0"}, transitions={"q0": {"i0": {"q0"}}}, initial_state="q0",
          final_states={"q0"})
VisualNFA(nfa).show_diagram(view=True)

Expected Behavior

The automaton is shown.

Actual Behavior

Traceback (most recent call last):
  File "/path/to/scratch_1.py", line 6, in <module>
    VisualNFA(nfa).show_diagram(view=True)
  File "/path/to/site-packages/visual_automata/fa/nfa.py", line 619, in show_diagram
    all_transitions_pairs = self._transitions_pairs(self.nfa.transitions)
  File "/path/to/site-packages/visual_automata/fa/nfa.py", line 469, in _transitions_pairs
    all_transitions = all_transitions.deepcopy()
AttributeError: 'frozendict.frozendict' object has no attribute 'deepcopy'

Cannot reproduce DFA example: Infinite language

Hey,

I cannot reproduce the example given from https://pypi.org/project/visual-automata/#visualdfa
Upon the call of VisualDFA(dfa) on the dfa

dfa = DFA(
states={"q0", "q1", "q2", "q3", "q4"},
input_symbols={"0", "1"},
transitions={
"q0": {"0": "q3", "1": "q1"},
"q1": {"0": "q3", "1": "q2"},
"q2": {"0": "q3", "1": "q2"},
"q3": {"0": "q4", "1": "q1"},
"q4": {"0": "q4", "1": "q1"},
},
initial_state="q0",
final_states={"q2", "q4"},
)

I get the following error:

InfiniteLanguageException: The language represented by the DFA is infinite.

I use the following versions:

automata-lib 8.0.0
visual-automata 1.1.1

Thanks for taking care already

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.