Ludii Forum
closeIA() - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Suggestions (https://ludii.games/forums/forumdisplay.php?fid=10)
+--- Forum: Ludii Features / Services (https://ludii.games/forums/forumdisplay.php?fid=11)
+--- Thread: closeIA() (/showthread.php?tid=21)

Pages: 1 2


closeIA() - Quentin Cohen-Solal - 01-29-2020

The util.AI class should have a closeIA() method, called automatically when reloading (before a new initIA()) or when changing the IA, in order to free up any used resources.

Thank you.


RE: closeIA() - DennisSoemers - 01-29-2020

Good idea, we'll include that. Probably in our next version.

Hmm, will have to put some thought into exactly when we call the method though. In the case of programmatic users of Ludii (using Ludii as a library for experiments etc.), it's fairly simple.

When loading the AI in the GUI (for instance for human vs. AI playing), there are some subtleties. In a normal game from start to finish, we always call the init at start, and could call close at the end (or right before the next init I suppose). But if a human chooses to step back a few moves, and then the AI starts playing again from that previous point onwards, we also always call initAI() again. The built-in MCTSes use this for example to ensure they stop using a now-invalid search tree built up from previous turns. This means we could also get closeAI() calls in the middle of a game sometimes. Not really a problem I suppose, just something to keep in mind...


RE: closeIA() - Quentin Cohen-Solal - 11-15-2020

Hello,

I have a problem with closeIA(). I would like to know when is it called. For example, I don't have the impression that it is called at the end of a game (which is not necessarily annoying). I also don't have the impression that it is called if we change opponents. If these are normal behaviors, then it would be nice to have a button to stop the AI (e.g. a square button next to the triangle button). On the other hand, much more problematic, I do not have the impression that it is called when closing the ludii application (if this is the case, then all unfinished AIs should be closed).

Moreover, as described in the previous post, is closeIA() effectively called before an initAI() that takes place during the game ?

Finally, It would be nice to have a setting in class IA to disable reset (and the corresponding closing) following rollback (I would like my IAs to keep their memory in case of undoing moves).

Thank you.


RE: closeIA() - DennisSoemers - 11-16-2020

Currently, when working with the GUI, closeAI() gets called when:

1) You compile and load a different game (closeAI() first called on all the different AIs that may have been playing the previously-loaded game)
2) When hitting Ctrl+R or the button to fully Restart the current game (resetting to initial game state)
3) Called on an old AI right before it gets replaced by a new AI when selecting a new AI from the dropdown menu

Hmmm, you're right, it would definitely make sense to at least also call it on all AIs when the application is being terminated. Though I'm not 100% sure how cleanly we can guarantee that it always happens when the application closes due to like the user pressing Alt+F4 or otherwise exiting in an abnormal manner...

So, closeAI() is not always called before an initAI(). closeAI() is only called in the cases listed above. initAI() is called much more frequently, like also whenever re-init may be necessary to reset possibly-invalid memory due to the user taking steps back. I guess if in your case you do always need a closeAI() in such a case first, you can simply detect whether or not closeAI() has already been called since the last call to initAI(), and call it yourself if it hasn't already been called.

I'm not sure about adding a setting to prevent initAI() reset calls for rollbacks... if a user selects such a setting with one of our built-in AIs, they'll be likely to crash. Is there a way you can work around this issue? In theory you could just not do the work in initAI(), but instead do it in the beginning of selectAction(). There you get access to the Context, can use that to detect whether you're in an initial game state (or at least one in which your agent never made any moves yet), and only do the work in that case. But I suppose this is not great if the initialisation work you need to do is time-consuming...


RE: closeIA() - Quentin Cohen-Solal - 11-16-2020

Thank you for these remarks.

However, although selecting a new "true" AI from the dropdown menu calls closeIA(), I don't feel that choosing "Human" calls closeIA(). It's quite annoying, because, if I then re-select "From Jar" in the dropdown menu, it will create a new IA of the same class but the previous IA will not have been closed (and I don't see how correct that since it is not the same object).


RE: closeIA() - DennisSoemers - 11-16-2020

(11-16-2020, 07:49 PM)Quentin Cohen-Solal Wrote: Thank you for these remarks.

However, although selecting a new "true" AI from the dropdown menu calls closeIA(), I don't feel that choosing "Human" calls closeIA(). It's quite annoying, because, if I then re-select "From Jar" in the dropdown menu, it will create a new IA of the same class but the previous IA will not have been closed (and I don't see how correct that since it is not the same object).

Ah yes you're right we'll have that fixed in the next version.


RE: closeIA() - Quentin Cohen-Solal - 12-08-2020

If I'm not mistaken, closeIA() is not called when creating a game in remote mode.


RE: closeIA() - MatthewStephenson - 12-08-2020

Hi,

closeAI() will now be called when creating a remote game from the next release.

Cheers,
Matthew


RE: closeIA() - Quentin Cohen-Solal - 12-08-2020

Thank you.


RE: closeIA() - Quentin Cohen-Solal - 12-12-2020

If I'm not mistaken, closeIA() is not called when disconnecting from the remote mode.

Thank you.