caleb531 / automata

A Python library for simulating finite automata, pushdown automata, and Turing machines
https://caleb531.github.io/automata/
MIT License
348 stars 64 forks source link

Visualization methods called from command line installation #222

Closed irisdyoung closed 4 months ago

irisdyoung commented 5 months ago

Examining the object my_dfa from the first example directly (no str or dir or anything else) throws an error in the command line only installation (latest, on python 3.12.3, on mac):

ImportError: Missing visualization packages; please install coloraide and pygraphviz.

Is this for sure what you want? It also does return the str representation afterward, so it seems like the error could be downgraded to a warning that you're operating without visualization capabilities, and a pointer to the installation option with the necessary dependencies. Separate issue incoming on that note...

eliotwrobson commented 5 months ago

I'm a little confused as well, this seems to match the behavior when running in a jupyter notebook without the visualization dependencies installed, but not purely on the command line. Maybe the Mac command line automatically tries to render objects with these methods present?

I suppose we could raise a warning and then the functions will be a noop if these dependencies aren't present? I'm not really sure what other libraries do. @caleb531 any thoughts about this behavior?

caleb531 commented 5 months ago

@irisdyoung @eliotwrobson I'm not sure I understand the issue here. I pip install automata into a fresh virtualenv (Python 3.12.3 on macOS Sonoma, using Mac terminal), and then run the first example from the FA Examples page, I am able to run the machine without error.

# example1.py
from automata.fa.dfa import DFA

# DFA which matches all binary strings ending in an odd number of '1's
my_dfa = DFA(
    states={'q0', 'q1', 'q2'},
    input_symbols={'0', '1'},
    transitions={
        'q0': {'0': 'q0', '1': 'q1'},
        'q1': {'0': 'q0', '1': 'q2'},
        'q2': {'0': 'q2', '1': 'q1'}
    },
    initial_state='q0',
    final_states={'q1'}
)

try:
    while True:
        if my_dfa.accepts_input(input('Please enter your input: ')):
            print('Accepted')
        else:
            print('Rejected')
except KeyboardInterrupt:
    print('')
Screenshot 2024-05-16 at 2 01 50 PM
lwasser commented 4 months ago

linking this to our review - friends can you please link any issues / pr's related to the review back to the review issue so we have a traceable review? many many thanks!! these issues and discussion are fantastic!

eliotwrobson commented 4 months ago

@caleb531 I realize we haven't really come to a conclusion here, but should we close this as not planned and reopen if this comes up again? Neither of us was able to reproduce this issue, and nobody else has reported it, so I'm not sure we can really do anything at this point.

caleb531 commented 4 months ago

@eliotwrobson Agreed to close as not planned—we can always reopen if need be.