Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Agent getID outside of an init function #1220

Open
ptheywood opened this issue Aug 12, 2024 · 3 comments
Open

New Agent getID outside of an init function #1220

ptheywood opened this issue Aug 12, 2024 · 3 comments

Comments

@ptheywood
Copy link
Member

The current documentation for host functions & conditions > Agent Creation states that:

newAgent() returns an instance of HostNewAgentAPI, this can be used like other objects to set and get a new agent’s variables via setVariable() and getVariable(). Additionally, getID() can be used to retrieve the ID which will be assigned to the new agent.

I.e. this is what you will find if you want to find how to get the ID of a new agent.

If instead of doing this in an init function, but instead doing it outside of / prior to the Simulation existing, on a flamegpu::AgentVector_Agent, the `getID() method exists, but always returns 0 (because it has not been set yet, and can't be until it is associated with the Simulation).

This could either be documented, or possible an exception thrown if this method is used prior to the instance having it's actual ID set?

@Robadob
Copy link
Member

Robadob commented Aug 12, 2024

Should be documented as exception. I don't think it's possible to assume agent IDs outside of the CUDASimulation object, as this could lead to an ID collision (which would throw an exception), particularly given agent state vectors can be combined etc.

The exception to that rule is agent state input files, which may contain IDs but purge all agent state on load (iirc).

@ptheywood
Copy link
Member Author

It didn't throw when I did this unintentionally (started with init func, but switched to pre-init to avoid having to pass too many objects into an init func via file scoped variables), all agents just returned 0.

I agree it should throw as it can't be accurate, and be documented as throwing, plus probably mentioning in the user guide too.

@Robadob
Copy link
Member

Robadob commented Aug 12, 2024

It didn't throw when I did this unintentionally (started with init func, but switched to pre-init to avoid having to pass too many objects into an init func via file scoped variables), all agents just returned 0.

https://github.com/FLAMEGPU/FLAMEGPU2/blob/master/src/flamegpu/simulation/detail/CUDAAgent.cu#L179

Well that seems like a bug, when agents are passed to CUDAAgent, validation is (supposed to be) performed, which would be redundant if we were force zeroing them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants