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

Making COMOKIT Individual species extendable #40

Closed
chapuisk opened this issue Jun 12, 2020 · 10 comments
Closed

Making COMOKIT Individual species extendable #40

chapuisk opened this issue Jun 12, 2020 · 10 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request gama bug Bug which needs to be fixed in GAMA
Milestone

Comments

@chapuisk
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
Currently there is no way to extends Individual to add new attributes, action and reflexes without changing the code from COMOKIT

Describe the solution you'd like
It should be possible to define an Individual subspecies to be used as it is Individual from the model. It should be possible adding a parameter of the model string main_agent <- my_own_individual with species my_own_individual parent:Individual and creating COMOKIT main agent this way: create species(main_agent.name). After that, all dynamic that call Individual species (e.g. a ask statement) should be replaced with Individual+(Individual.subspecies accumulate each.population)

Describe alternatives you've considered
The alternative I currently work on implies encapsulating Individual into another external species that will have other attributes, action and reflexes and share all necessary things with their _inner_individual. However, it double the number of agent and makes initialization not an easy task (i.e. COMOKIT creates Individual with homeplaces, agendas, friends and so on, and after that you create you own species possibly relocating them, changing agendas and so on)

Additional context
The request will be useful to make COMOKIT even easier to extende

@chapuisk chapuisk added the enhancement New feature or request label Jun 12, 2020
@chapuisk chapuisk added this to the V2 milestone Jun 12, 2020
@AlexisDrogoul
Copy link
Contributor

RBD. First comment: we should never ever use strings to specify this kind of things. Do not forget that species is also a type. Second thing: we should never sacrifice readability for extendability. How can someone possibly understand something like Individual+(Individual.subspecies accumulate each.population) everytime there is a loop on individuals ?

So:

  1. I would define something like species<Individual> Individual_species <- Individual; by default
  2. create a global function called all_individuals that could replace the use of Individual in ask, loop and iterators.

I have committed a possible solution. Please check if it works (didn't try it with another species than Individual) and if it corresponds to your needs.

AlexisDrogoul added a commit that referenced this issue Jun 13, 2020
1) defines `species<Individual> Individual_species <- Individual;` by default
2) creates a global function called `all_individuals` that replaces the use of `Individual` in `ask`, `loop` and iterators.
@chapuisk
Copy link
Collaborator Author

Thanks Alexis ! I even did not think of using generic species ... This is nice. I'll try asap and get feedback here

@chapuisk
Copy link
Collaborator Author

Hey @AlexisDrogoul ! first, creation of requested species does work as the actual Individual species of my model is define by individual_species. However, there is several things to note:

  • The attribute must be redefine in before_init action, e.g. action before_init { individual_species <- my_sub_species; }. As expected, If it is define in global or init of a gaml file connected to COMOKIT, it does not work (exectured after init).
  • Action from Individual species in the initialization phase (mostly related to epidemiological status and network) are not triggered !!! I'll investigate further on this.
    Kevin

@chapuisk
Copy link
Collaborator Author

Hi @AlexisDrogoul with the help of @DAM-Philippon we (he) finally found the bug :
for some unidentified reasons, the species that extends Individual must also be explicitly granted the control:fsm facet in order to recognize the state inherited from BiologicalEntity. Otherwise it is set to nil !

@AlexisDrogoul
Copy link
Contributor

Nice job ! No time to dig this now but an issue in gama would be important to make (if possible with a simpler example)...

@chapuisk
Copy link
Collaborator Author

@AlexisDrogoul Unfortunately, I have not been able to reproduce the bug on a simpler model. @DAM-Philippon intuition is that it comes from the fact that both species are from separated Gama project ... I'll try to reproduce it, but not guaranteed to be able to do so with a "simpler" example

@AlexisDrogoul
Copy link
Contributor

How does the bug manifest itself exactly ? You see a nil value somewhere ? The state is initialised after your own variables are ?
One workaround to try: if control: fsm is added to Individual (in addition to BiologicalEntity, is it still happening ?

@AlexisDrogoul AlexisDrogoul added bug Something isn't working gama bug Bug which needs to be fixed in GAMA labels Jun 17, 2020
@DAM-Philippon
Copy link
Contributor

From what I remember when helping Kevin, both attributes state and states (the list of possible states) were set to nil.
We've tried to add both attributes directly to the species Refugee (which extends the Individual species), with default value just for testing. Interestingly, even those attributes with the values specified in the species Refugee (which should supersede the previous definition) were set to nil.

(I've tried to get a simple case for debugging, with two different projects, having different species inheriting in two different levels, but I didn't get the bug)

I don't know what we would get by adding control:fsm to Individual.

@AlexisDrogoul
Copy link
Contributor

OK. I'm sorry, but there is a lot of confusion here and I don't really get what goes wrong. @chapuisk tells that the new species doesn't recognize the state inherited from BiologicalEntity (whatever that means: error in the execution ? in the compilation ?); @DAM-Philippon writes that state and states (the list of possible states) were set to nil, which means they are recognised after all... How did you find this ? Is it possible, if you can't create a simpler bug, to at least share with me the failing project ?

AlexisDrogoul added a commit to gama-platform/gama.old that referenced this issue Jun 17, 2020
The control of parent species may not have been correctly initialized
before child species try to determine theirs. The finalization of
control is now enforced in parent species.
@chapuisk
Copy link
Collaborator Author

As far as I can see running my models, the child species now inherit control architecture as expected. I then close the issue. Thx @AlexisDrogoul !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request gama bug Bug which needs to be fixed in GAMA
Projects
None yet
Development

No branches or pull requests

4 participants