-
Notifications
You must be signed in to change notification settings - Fork 269
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
Import Fortran Strategies #381
Comments
Why not just implement the remaining strategies in Python? |
They range from easily translatable to borderline unintelligible. The lack of comments also makes it difficult to know if we've implemented them correctly. |
An extra complication is that all internal variables in the Fortran functions maintain their state between invocations. This was handled orginally using "a. the -SAVEALL option must be used in the Language Systems Fortran compiler to make the local variables in the rule functions static (ie remembers from one call to the next)." It's done now within gfortran by passing the I can't find any material to describe how numpy handles that requirement. My suspicion is that it doesn't. |
My current line of thought is that I'd prefer us not to automatically load in the Fortran code:
I think it's brilliant to have them and have them working but I feel that we should use them to write the corresponding Python/Axelrod class. One potential option would be to write some sort of wrapper in another library that did translate them AS IS to Python classes that can be used in axelrod with the "disclaimer" that that's what that's doing. So for example a user could run:
and then:
That way we're still claiming that everything in the Axelrod library is written to a high quality and completely tested. We would theoretically, slowly slowly translate the strategies in |
I agree with the thoughts above. I'm also not entirely convinced the import is possible because of the issue with persistence of state. (Although that may just be that I haven't yet found how to cope with that). |
I would be in favor of automatic loading (so we have them, or at the user's discretion), translating each to python implementations with sufficient test coverage. For the state retention issue, could we reload in the |
Testing them is one thing, readability and cohesiveness is the other.
Would the suggestion of an optional library be ok for this? (Like my suggestion for |
Yes. Do we know if it's even possible to import the Fortran yet? |
A little further research: https://docs.scipy.org/doc/numpy-1.10.1/user/c-info.python-as-glue.html Extension modules is the method f2py (and now, numpy) uses. There is some guidance at http://www.fortran90.org/src/best-practices.html#interfacing-with-python for using the ctypes module with Fortran. Essentially, the extension module approach works with the fortran code directly, whilst the ctypes approach works with the compiled object files. I don't know how we would handle the state persistence issue using extension modules. It's not clear to me how the compilation stage is handled and how, therefore, I would pass the instruction to keep function variable values between invocations. My gut feel is that the ctypes approach is the way to go. That way, I can control the compilation of the Fortran code into object files and pass the necessary flag. |
So, my thoughts at the moment are to compile the strategy functions that we wish to import into a single shared object file which is then called from within Python using the ctypes module. As we translate strategies into Python properly, we remove them from the list of those we compile. Update And, yes, I think that the suggestion by @drvinceknight to use a separate |
Side Note: Whilst some (many?) of the Fortran strategies are indecipherable, that doesn't mean we can't translate them to Python - we could just do a 'literal' translation line by line. We'd end up with the most un-pythonic Python code you've ever seen, but it would work. Writing tests would be almost impossible, because we'd still have little idea of the intention behind the strategy. However, if my idea of using a shared object file and the ctypes module works, it gives us the possibility of at least writing tests to assert that the translated Python strategy behaves in the same way as the original Fortran. |
Further research: https://docs.scipy.org/doc/numpy-dev/f2py/usage.html#command-f2py shows that f2py has options to pass flags to the compiler: --f77flags=
--f90flags=
So, both f2py (numpy) and ctypes look like viable options |
This all sounds great to me. I also understand very little about it though :)
👍 It'll be awesome to have these run if indeed it's possible to do so. Potentially a paper in itself just about reviving the code and running the tournament :) |
I think you'd find this difficult, what with all the implicit GOTOs in the compound if statements.
Indeed! And we can add our ML-strategies to the mix for a nice validity test (since they've never seen most of the original tournament strategies). |
Can I be so bold as to suggest we can now close this one?!!! |
Yeah I think this can be closed. I'll add a comment to #379 and then we can open up specific individual issues for translating specific strategies 👍 Great work @meatballs! |
Given the original Axelrod tournament #2 source code, we should be able to wrap the Fortran using numpy. This would net the 64 strategies from that tournament as is.
To proceed we'll need to (at least):
FUNCTION K49R(J,M,K,L,R, JA)
whereThis is different than what we give players now (the full history, we don't track the cumulative score, etc.)
The text was updated successfully, but these errors were encountered: