Skip to content

Commit

Permalink
deploy: 9ef8afb
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Oct 7, 2023
0 parents commit ff430c1
Show file tree
Hide file tree
Showing 219 changed files with 44,244 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 6d97bff16ae9beb932d4861490b5a9cd
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/agent-functions/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/creating-a-model/index.doctree
Binary file not shown.
Binary file added .doctrees/guide/debugging-models/index.doctree
Binary file not shown.
Binary file added .doctrees/guide/debugging-models/logging.doctree
Binary file not shown.
Binary file added .doctrees/guide/debugging-models/print.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/defining-agents/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/environment/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/flamegpu2-source/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/host-functions/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/telemetry/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/guide/visualisation/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/quickstart/index.doctree
Binary file not shown.
Binary file added .doctrees/tutorial/index.doctree
Binary file not shown.
Empty file added .nojekyll
Empty file.
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs.flamegpu.com
Binary file added _images/NB_MYCNx512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/NB_cycle_stages_6x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/NB_living_countx512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/NB_telo_countx512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/cmake-generator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/cmake-gui-annotated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<map id="%3" name="%3">
</map>
Binary file added _images/ui-collapsed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/ui-full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/visual_studio_build_config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/visual_studio_start_debugger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _images/visual_studio_startup_project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
176 changes: 176 additions & 0 deletions _sources/guide/agent-functions/agent-birth-death.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
.. _agent birth death:

Agent Birth & Death
^^^^^^^^^^^^^^^^^^^

By default agents within FLAME GPU cannot die or create new agents. In order to enable the checks and processing required for either of these operations, they must be enabled first.

Agent Death
-----------

When an agent in FLAME GPU is killed, it is removed from the simulation and all data held in the agent's variables is discarded.

Enabling Agent Death
====================

By default in FLAME GPU 2 agents do not die. To enable death for a particular agent function, use the :func:`setAllowAgentDeath()<flamegpu::AgentFunctionDescription::setAllowAgentDeath>` method of
the :class:`AgentFunctionDescription<flamegpu::AgentFunctionDescription>` that you would like to enable death for:

.. tabs::

.. code-tab:: cpp C++

flamegpu::AgentFunctionDescription agent_fn1_description = agent.newFunction("agent_fn1", agent_fn1);
// Allow agent_fn1 to kill agents
agent_fn1_description.setAllowAgentDeath(true);

.. code-tab:: py Python

agent_fn1_description = agent.newRTCFunction("agent_fn1", agent_fn1_source);
# Allow agent_fn1 to kill agents
agent_fn1_description.setAllowAgentDeath(True)

When this agent function is then added to a layer or dependency graph, it will support agent death.


Killing Agents via Agent Functions
==================================

To have an agent die, simply return :enumerator:`flamegpu::DEAD<flamegpu::AGENT_STATUS::DEAD>` (``pyflamegpu.DEAD`` in Python) instead of :enumerator:`flamegpu::ALIVE<flamegpu::AGENT_STATUS::ALIVE>` (``pyflamegpu.ALIVE`` in Python) at the end of a death-enabled agent function. You can use conditionals to only have agents die according to a certain condition:

.. tabs::

.. code-tab:: cuda Agent C++

FLAMEGPU_AGENT_FUNCTION(agent_fn1, flamegpu::MessageNone, flamegpu::MessageNone) {
// Get the 'x' variable of the agent
int x = FLAMEGPU->getVariable<int>("x");

// Kill any agents with x < 25
if (x < 25) {
return flamegpu::DEAD;
} else {
return flamegpu::ALIVE;
}
}

.. code-tab:: py Agent Python

@pyflamegpu.agent_function
def agent_fn1(message_in: pyflamegpu.MessageNone, message_out: pyflamegpu.MessageNone):
# Get the 'x' variable of the agent
x = pyflamegpu.getVariableInt("x")

# Kill any agents with x < 25
if (x < 25) :
return pyflamegpu.DEAD
else :
return pyflamegpu.ALIVE


If :enumerator:`flamegpu::DEAD<flamegpu::AGENT_STATUS::DEAD>` (``pyflamegpu.DEAD`` in Python) is returned by an agent function whilst agent death is not enabled the agent will not die. If ``FLAMEGPU_SEATBELTS`` error checking is enabled an exception will be raised.


Agent Birth
-----------
The agent creation interface usable in agent functions is only able to create a single agent per existing agent per iteration.
Additionally, the type (and state) of the agent being created must be earlier specified as part of the model description (a single agent function can only output one specific agent type and state). Agent's can also be created via host functions, that may be more applicable in cases where many agents must be created from a single source.

Agent birth from agent functions is always considered optional, any agent which sets an output agent's variables will cause the output agent to be created.

.. note::
Agents created by agent functions do not exist until the next layer.

Enabling Agent Birth
====================

To create agents from agent functions, you must specify the type of agent the function produces when defining your agent functions, by passing it a reference to the :class:`AgentFunctionDescription<flamegpu::AgentFunctionDescription>`. If using states you can additionally specify the state the agent should be created within:

.. tabs::

.. code-tab:: cpp C++

// Create a new agent type 'example_agent'
flamegpu::AgentDescription example_agent = model.newAgent("example_agent");

...

// The agent type 'example_agent' is set as the agent output type
// To be output in the default state
agent_fn1_description.setAgentOutput(example_agent);

// The agent type 'example_agent' is set as the agent output type
// To be output in the state 'living'
agent_fn2_description.setAgentOutput(example_agent, "living");

.. code-tab:: py Python

# Create a new agent type 'example_agent'
example_agent = model.newAgent("example_agent")

...

# The agent type 'example_agent' is set as the agent output type
# To be output in the default state
agent_fn1_description.setAgentOutput(example_agent)

# The agent type 'example_agent' is set as the agent output type
# To be output in the state 'living'
agent_fn2_description.setAgentOutput(example_agent, "living")

Creating Agents via Agent Functions
===================================

When agent output has been enabled for an agent function, the :class:`FLAMEGPU->agent_out<flamegpu::DeviceAPI::AgentOut>` (``pyflamegpu.agent_out`` in Python) object will become available within agent
function definitions. This can be used to initialise the properties of the newly created agent.

Much like the agent's variables, :func:`setVariable()<flamegpu::DeviceAPI::AgentOut::setVariable>` can be used on this object, to set the new agent's variables. Additionally, :func:`getID()<flamegpu::DeviceAPI::AgentOut::getID>` may be used to retrieve the new agents future ID.

Agent variables which are not manually set will be initialised with their default values.

Agent creation is always optional once enabled, a new agent will only be marked for creation when either :func:`setVariable()<flamegpu::DeviceAPI::AgentOut::setVariable>` or :func:`getID()<flamegpu::DeviceAPI::AgentOut::getID>` are called.

.. tabs::

.. code-tab:: cuda Agent C++

FLAMEGPU_AGENT_FUNCTION(OptionalOutput, flamegpu::MessageNone, flamegpu::MessageNone) {
// Fetch this agent's id
flamegpu::id_t id = FLAMEGPU->getID();

// If its id is even, output a new agent, otherwise do nothing
if (id % 2 == 0) {
// Output a new agent with its 'x' variable set to 500.0f
FLAMEGPU->agent_out.setVariable<float>("x", 500.0f);
}

// Other agent function code
...
}

.. code-tab:: py Agent Python

@pyflamegpu.agent_function
def OptionalOutput(message_in: pyflamegpu.MessageNone, message_out: pyflamegpu.MessageNone):
# Fetch this agent's id
id = pyflamegpu.getID()

# If its id is even, output a new agent, otherwise do nothing
if id % 2 == 0 :
# Output a new agent with its 'x' variable set to 500.0f
pyflamegpu.agent_out.setVariableFloat("x", 500.0f)

# Other agent function code
...

If :class:`FLAMEGPU->agent_out<flamegpu::DeviceAPI::AgentOut>` is used in an agent function which has not had agent output enabled, no agent will be created. If ``FLAMEGPU_SEATBELTS`` error checking is enabled, an exception will be raised.

Related Links
-------------

* User Guide Page: :ref:`Defining Agents<Defining Agents>`
* User Guide Page: :ref:`Agent Operations<Host Agent Operations>` (Host Functions)
* User Guide Page: :ref:`What is FLAMEGPU_SEATBELTS?<FLAMEGPU_SEATBELTS>`
* Full API documentation for :class:`AgentFunctionDescription<flamegpu::AgentFunctionDescription>`
* Full API documentation for :class:`AgentOut<flamegpu::DeviceAPI::AgentOut>`
* Full API documentation for :class:`DeviceAPI<flamegpu::DeviceAPI>`
Loading

0 comments on commit ff430c1

Please sign in to comment.