How to set the messages before the simulation begins? #1128
-
Hi, I would like to set the messages with custom values for each agent before the simulation starts. How would it be possible to achieve this in Python? Kind Regards, John. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
It's not currently possible to initialise messages from the host, they can only be output by agents and we don't currently have on-device/agent initialisation functions (#329) where you could create such messages. To emulate this behaviour you could create your agents in an initial state "init", which only runs for one agent function whereby these initial messages are output. The same function should also transition the agents from "init" state to some other state e.g. "ready", which all the other agent functions have as their begin/end state. The user guide's coverage for this flow is currently lacking (I will try to find time to address this today FLAMEGPU/FLAMEGPU2-docs#169). Some relevant links:
The code would roughly look # todo declare messages
agent= model.newAgent("agent")
# todo declare vars
agent.newState("init")
agent.newState("ready")
# Create the initialiser agent function, which ouputs messages
af1 = a.newRTCFunction("init_function", InitFn_source)
af1.setInitialState("init")
af1.setEndState("ready")
af1.outputdata.setMessageOutput("init_message")
# Create remaining agent functions
af2 = a.newRTCFunction("behaviour_function", BehaviourFn_source)
af2.setInitialState("ready")
af2.setEndState("ready")
# Setup the execution order of functions
model.newLayer().addAgentFunction(af1)
model.newLayer().addAgentFunction(af2)
# Create initial agents in the "init" state
# Create a population of 1000 agents
population = pyflamegpu.AgentVector(agent, 1000)
# todo initialise the agents
# Add the agents to a simulation in "init" state and execute
simulation = pyflamegpu.CUDASimulation(model)
simulation.setPopulationData(population, "init")
simulation.initialise(sys.argv)
simulation.simulate() Unclear what you require this for, so it seems worth additionally highlighting this quote from the user guide:
|
Beta Was this translation helpful? Give feedback.
-
Many thanks for your detailed response which is really helpful. The initial state of all agents needs to be known for the agents to decided on their next state. Since I believe agents can't communicate directly they will need to find the neighbour states from the message array at fixed indices. Different simulations will have set stating states to better understand how initial states lead to quicker ordered convergence. The simulation will have 250,000+ agents running on Nvidia Tesla hardware. |
Beta Was this translation helpful? Give feedback.
It's not currently possible to initialise messages from the host, they can only be output by agents and we don't currently have on-device/agent initialisation functions (#329) where you could create such messages.
To emulate this behaviour you could create your agents in an initial state "init", which only runs for one agent function whereby these initial messages are output. The same function should also transition the agents from "init" state to some other state e.g. "ready", which all the other agent functions have as their begin/end state.
The user guide's coverage for this flow is currently lacking (I will try to find time to address this today FLAMEGPU/FLAMEGPU2-docs#169).
Some rele…