Open christianechevarria opened 5 years ago
Looks like this bug may still exist?
It seemed that 0.3.14 was working for me, but I may have been mistaken, as it's failing for me again.
I've been trying to write a test case which fails (as opposed to posting all of my app code), but I've not been successful yet. Will continue to work on this.
One more clue is that when the "threads" option for evolve() is set, it will crash my app. When "threads" is not specified, it doesn't crash, but hangs, doing nothing.
Also possibly related (and probably really a javascript/node question): What's the best/preferred way to require the carrot module? Does it matter?
const carrot = require("@liquid-carrot/carrot"); const network = new carrot.Network(2,1);
or
const { Network, methods } = require("@liquid-carrot/carrot"); const network = new Network(2,1);
@tracycollins Will look more into this...
What environment are you using it in (i.e. Browser, Node, etc.)?
The import shouldn't make a difference...for personal styling I tend to use:
const carrot = require("@liquid-carrot/carrot");
const network = new carrot.Network(2,1);
@luiscarbonell I'm using node.
I also prefer the same style. Wasn't sure if it made any difference. Thanks
Finally created an example of the bug:
const neataptic = require("neataptic");
const carrot = require("@liquid-carrot/carrot");
async function main(){
const numInputs = 2;
const numOutputs = 1;
const network = new carrot.Network(numInputs, numOutputs);
// const network = new neataptic.Network(numInputs, numOutputs);
const trainingSet = [];
for(let j=0; j<5; j++){
const datum = {};
datum.input = [];
datum.output = [];
for(let i=0; i<numInputs; i++){
const inputValue = Math.round(Math.random());
datum.input.push(inputValue);
}
for(let i=0; i<numOutputs; i++){
const outputValue = Math.round(Math.random());
datum.output.push(outputValue);
}
trainingSet.push(datum);
}
console.log("trainingSet\n" , trainingSet);
const options = {
mutation: carrot.methods.mutation.FFW,
error: 0.05,
equal: true,
elitism: 5,
mutation_rate: 0.5,
iterations: 10,
log: 1,
threads: 1,
};
console.log("options\n" , options);
try{
const results = await network.evolve(trainingSet, options)
console.log("results\n", results);
console.log("network.activate(trainingSet[0]: " + network.activate(trainingSet[0].input));
return;
}
catch(err){
console.trace(err);
throw err;
}
}
main();
Fails using carrot 0.3.12+, Passes using carrot 0.3.11 Also passes using neataptic
Trace: TypeError: Cannot read property 'join' of undefined at new c (/Volumes/RAID1/projects/twitterNeuralNetwork/node_modules/@liquid-carrot/carrot/dist/carrot.commonjs2.min.js:36:127497) at p.evolve (/Volumes/RAID1/projects/twitterNeuralNetwork/node_modules/@liquid-carrot/carrot/dist/carrot.commonjs2.min.js:36:91723) at main (/Volumes/RAID1/projects/twitterNeuralNetwork/carrotTest.js:49:35) at Object.
(/Volumes/RAID1/projects/twitterNeuralNetwork/carrotTest.js:60:1) at Module._compile (internal/modules/cjs/loader.js:936:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10) at Module.load (internal/modules/cjs/loader.js:790:32) at Function.Module._load (internal/modules/cjs/loader.js:703:12) at Function.Module.runMain (internal/modules/cjs/loader.js:999:10) at internal/main/run_main_module.js:17:11 at main (/Volumes/RAID1/projects/twitterNeuralNetwork/carrotTest.js:55:13) at processTicksAndRejections (internal/process/task_queues.js:85:5) (node:99735) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'join' of undefined at new c (/Volumes/RAID1/projects/twitterNeuralNetwork/node_modules/@liquid-carrot/carrot/dist/carrot.commonjs2.min.js:36:127497) at p.evolve (/Volumes/RAID1/projects/twitterNeuralNetwork/node_modules/@liquid-carrot/carrot/dist/carrot.commonjs2.min.js:36:91723) at main (/Volumes/RAID1/projects/twitterNeuralNetwork/carrotTest.js:49:35) at Object. (/Volumes/RAID1/projects/twitterNeuralNetwork/carrotTest.js:60:1) at Module._compile (internal/modules/cjs/loader.js:936:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10) at Module.load (internal/modules/cjs/loader.js:790:32) at Function.Module._load (internal/modules/cjs/loader.js:703:12) at Function.Module.runMain (internal/modules/cjs/loader.js:999:10) at internal/main/run_main_module.js:17:11 (node:99735) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:99735) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Also, if options.threads is removed, then nothing happens
@tracycollins Just got settled in after a flight, man this is a greatly structured bug report -- much love on the effort you put in here 🙏
I'm going to add this as a test case immediately and start retracing the changes between v0.3.11
and v0.3.12
I've had my suspicions on the culprit being our new webpack bundling approach for the node build. The entry used to just be the unminifed carrot.js file inside the src/ folder but that is one of the changes we made for v0.3.12
Will report back with new insights or updates
Also, let's see if this thing works: @all-contributors please add @tracycollins for his work with tests
@christianechevarria
I've put up a pull request to add @tracycollins! :tada:
@tracycollins Just got settled in after a flight, man this is a greatly structured bug report -- much love on the effort you put in here 🙏
I'm going to add this as a test case immediately and start retracing the changes between
v0.3.11
andv0.3.12
I've had my suspicions on the culprit being our new webpack bundling approach for the node build. The entry used to just be the unminifed carrot.js file inside the src/ folder but that is one of the changes we made forv0.3.12
Will report back with new insights or updates
Update: Noticed that even though we updated the dist to use the commonjs2.min.js
following the webpack build changes we made in v0.3.12
we didn't update the tests to require that file instead of the unbuilt source file src/carrot.js
As soon as the change gets made we get the error brought up in https://github.com/liquidcarrot/carrot/issues/160
Seems like the build error is coming from the issue mentioned in this thread -- temporarily reverting the file entry point to carrot.js
in package.json
and updating the default jsdelivr
file
⚠️ Until this is fixed the commonjs2
dist is not to be used
Inside of testworker we're requiring worker.js using a relative filepath which makes an assumption about the file's location
This approach is prone to bugs and doesn't allow for a standalone build of the library: https://github.com/liquidcarrot/carrot/blob/ad3c6c04f763e4bcf91e5d76fc7819357bfcaade/src/multithreading/workers/node/testworker.js#L35-L37
Originally posted by @christianechevarria in https://github.com/liquidcarrot/carrot/issues/160#issuecomment-532806547