A-Grunder

A-Grunder

Hello,

I am writing a cellualr automata system in elixir. I think that the problem comes from the cell supervisor (DynamicSupervisor) not creating the cells

This is the repository of my code : https://github.com/A-Grunder/Cellular-Automata-in-Elixir.

Showing Posts 1 to 6

dimitarvp

dimitarvp

While it’s nice you posted a GitHub repo proving what you need does not work, it’s still considered polite to demonstrate you have made an effort to fix the problem(s).

What have you tried?

al2o3cr

al2o3cr

None of the Cell processes ever start because they try to register with a registry that isn’t started (or even defined):

https://github.com/A-Grunder/Cellular-Automata-in-Elixir/blob/3ba53ba3efa445e08d0dabc0e401c3918ad66e59/lib/cell.ex#L112

You’ll need a line like:

{Registry, keys: :unique, name: CellularAutomata.Cell.Registry}

in your supervision tree.

I also suspect you’ll want to call Registry.update_value rather than register here, since passing the via tuple to GenServer.start_link as name will already have done the registration.

al2o3cr

al2o3cr

Closing out tabs and I noticed the updates to the repo - looks like the next headache is going to be timeouts:

08:33:34.984 [error] GenServer #PID<0.228.0> terminating
** (stop) exited in: GenServer.call(CellularAutomata.World, :get_grid, 5000)
    ** (EXIT) time out
    (elixir 1.16.2) lib/gen_server.ex:1114: GenServer.call/3
    (cellular_automata 0.1.0) lib/scenes/home.ex:25: CellularAutomata.Scene.Home.init/3
    (scenic 0.11.2) lib/scenic/scene.ex:1335: Scenic.Scene.handle_continue/2
    (stdlib 5.2.1) gen_server.erl:1085: :gen_server.try_handle_continue/3
    (stdlib 5.2.1) gen_server.erl:995: :gen_server.loop/7
    (stdlib 5.2.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:continue, {:_init, [supervisor: #PID<0.226.0>, stop_pid: #PID<0.226.0>, child_supervisor: nil, name: "_main_", module: CellularAutomata.Scene.Home, parent: #PID<0.220.0>, param: nil, viewport: %Scenic.ViewPort{name: :main_viewport, pid: #PID<0.220.0>, script_table: #Reference<0.2747193118.4261019661.20982>, size: {800, 600}}, root_sup: #PID<0.222.0>, opts: [theme: :dark]]}}
State: nil

08:33:34.990 [error] Scene exited or crashed before it was done initializing.
pid: #PID<0.228.0>, reason: {:timeout, {GenServer, :call, [CellularAutomata.World, :get_grid, 5000]}}
module: CellularAutomata.Scene.Home, id: "_main_"

The root cause is that between line 20 and line 25, the World process is starting 250,000 Cell processes. The handle_cast for :start_state doesn’t return control to the GenServer receive loop until that’s done, so the message sent by World.get_grid doesn’t get handled within GenServer.call’s default 5-second timeout.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Following up on this, I don’t think a process per cell is a particularly good model for how cellular automata work. There’s no real concurrency in play, as the whole program has to operate in a stepwise fashion. Each cell depends on the state of the previous cell, which if those are different processes will result in a lot of message passing.

Now, from a “let’s play with it” standpoint, go for it! But may lower the process count to start with to make debugging easier, and grow it as you gain confidence in how the program is working.

heilong

heilong

You are technically correct for existing definitions of CA, but …

  1. It should be possible for each cell to keep previous/current values as state, execute updates with messages, then roll the state when it has provided prev to all neighbors, and updated curr from all neighbors, e.g. a simple countdown message counter state for each generation, and a monotonic generation counter ID state also provided in all messages.

  2. Asynch CA is much more interesting to me, because the real world is async. Sure the actual results will depend on BEAM scheduler and the random seed, but evolving structure, statistics and stability would be fascinating (not to appeal to authority, but joearms was a physicist and I’m sure he would agree).

P.S. Apologies, I have not looked at the repo, and have not searched for previous work on Asynch CA.

heilong

heilong

I have put up a quick hack to illustrate 1 & 2:

https://github.com/mike-french/expaca

There are synch and asynch simulations using GoL rule,
with output to bitmaps, images and video/gif
(if you have ffmpeg installed).

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews