import amachine as am

am.srand_global(42)

m = am.random_machine( 
        n_states=11, 
        symbols=[ '0', '1', '2' ],
        connectedness=0.65,
        randomness=0.37 )

# Collapse to the largest recurrent subgraph
m.collapse_to_largest_strongly_connected_subgraph()

# Minimize the machine -> epsilon-machine.
m.minimize()

# Create an isomorphic machine with new labels
m_iso = am.isomorphic_to( m, alphabet=[ '3', '4', '5' ] )

m_iso.isoclass = 0
m.isoclass     = 0

for j, state in enumerate( m.states ) : 
    m.states[ j ].add_isomorph( m_iso.states[ j ].name )
    m_iso.states[ j ].add_isomorph( m.states[ j ].name )
    
# Join them together
m_star = am.star_join(
    exit_symbol='x', 
    enter_symbols=['a','b' ],
    machines=[ m, m_iso ],
    mode_residency_factor=0.75 
)

m_star.draw_graph(output_dir="./")

m_star.generate_data(
    file_prefix="./data/iso_012-345", # saves as iso_012-345.parqet
    n_gen=2_000, 
    include_states=True,
    isomorphic_shifts={1}
)