Comments (12)
Can you run:
python3 ponyge.py --fitness_function string_match
Notice we just use string_match
, not string_match.py
.
Also, to run this we have to be in the src
directory.
from ponyge2.
Yes I can run that.
Sorry I had tried with and without .py and still getting the error
from ponyge2.
I also tried copying the file string_match.py
to string_match2.py
(and of course changing the name inside the file also). And now python3 ponyge.py --fitness_function string_match2
also works for me. So the mechanism is working as expected. I have to suspect something in the file xxx.py
- either location, name, or name inside the file is not as expected. Would you like to post it?
from ponyge2.
Yeah I just tried to copy the string match and changed the name and it works fine. I'll include my fitness function.
from fitness.base_ff_classes.base_ff import base_ff
import time
from DOOMGame import mybehaviours
class doom_fitness(base_ff):
def __init__(self):
super().__init__()
def evaluate(self, ind, **kwargs):
p = ind.phenotype
print("\n" + p)
fitness = 0
for trial in range(50):
self.test_spec = getSpec()
# generatelist should be the hand coded one
d = {'test_spec': self.test_spec}
try:
t0 = time.time()
exec(p, d)
# algo p, parameters in d
t1 = time.time()
guess = d['return']
print (guess)
fitness += len(p)
# adding length of p to represent complexity of algorithm
#run game passing guess as the created tree
# I know it's not finished here but that shouldn't affect the module not found I don't think
except:
fitness = self.default_fitness
break
return fitness
def getSpec():
return mybehaviours.npcSpec()
from ponyge2.
I removed my usage of function from the mybehaviours file and i could run my program. Is there any way I can import functions?
from ponyge2.
Yes. If the module you want to import is installed system-wide it should work directly. If it's in the source tree, then at least it works if it's in the current directory. So, if I put this in string_match.py
, and I put test.py
in src
, then it works:
from test import f
But if I put test.py
in fitness
, it doesn't work.
from ponyge2.
The function I want to access is in a file in a directory which is inside src.
As soon as I add the function to the fitness file I get module not found without the import it runs without that error
from ponyge2.
The code will run if I place a test file in src.
The issue seems to be when the file is in a directory which is a child of src
from ponyge2.
This works:
python3 ponyge.py --fitness_function string_match2
Where string_match2.py
is in fitness
, and it runs:
from fitness.testdir.test import f
and fitness/testdir
includes the file test.py
.
I'm not very clever at Python sub-modules etc., but yes, it seems to be possible!
from ponyge2.
I've been playing around with it and it seems to working now.
I was trying to import from a fairly large package and the error seemed to be coming from having an init.py in the subpackage. Thank you for your help :)
from ponyge2.
The issue seems to persist if I'm importing in the file I'm importing. It seems to be a mess of python submodules
from ponyge2.
My example above seems to show hot to import from within the import. So I believe this can be closed but please reopen if there is something specific not working.
from ponyge2.
Related Issues (20)
- Default example doesn't run HOT 5
- Examples not working HOT 2
- `regex_improvement.txt` example - confusing message? HOT 1
- `seed_run_target.txt` example doesn't work
- Please help with solution min/max boundaries ❓ HOT 6
- Tree initialisation breaks when min = max depth
- Tree initialisation operators sometimes don't achieve stated depth
- Progsys with "Compare String Lengths" not giving valuable results
- Rethink if-else-classifier?
- progsys Digits problem
- progsys 'is' and 'is not' HOT 3
- missing contents of String Differences-Embed.txt HOT 1
- Statistics parser prog in Wiki incorrectly named
- save_state not working with multicore
- load_state not working with functions in custom module
- Post-processing python phenotypes is slow
- correct genome not returned when one of the codons is zero in the tree
- progsys count odds data
- Multi-objective optimisation is slow HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ponyge2.