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

fail running Launcher.Legacy for python algorithm #10

Open
anaderi opened this issue Jul 25, 2020 · 5 comments
Open

fail running Launcher.Legacy for python algorithm #10

anaderi opened this issue Jul 25, 2020 · 5 comments

Comments

@anaderi
Copy link

anaderi commented Jul 25, 2020

I've cloned both Lean (master branch) and this repo as documentation suggests. Launcher successfully optimization of Csharp algorithm (ParameterizedAlgorithm from Jtc.Optimization.LeanOptimizer.Example.dll), but as I switch to Python mentioned in readme (ParameterizedSharedAppDomainAlgorithm, "../../../Jtc.Optimization.LeanOptimizer.Example/ParameterizedSharedAppDomainAlgorithm.py") I get core dumped:

ts-01:~/git/LeanParameterOptimization/Jtc.Optimization.Launcher.Legacy/bin/Debug$ mono Jtc.Optimization.Launcher.Legacy.exe optimization.json
PythonEngine.Initialize(): Runtime.Initialize()...
Runtime.Initialize(): Py_Initialize...
PythonEngine.Initialize(): Runtime.Initialize()...
Runtime.Initialize(): PyEval_InitThreads...
Runtime.Initialize(): Initialize types...

=================================================================
	Native Crash Reporting
=================================================================
PythonEngine.Initialize(): Runtime.Initialize()...
Runtime.Initialize(): Initialize types...
Aborted (core dumped)

Meanwhile Lean (master branch) runs Python algorithms without a flaw. Please advise.

@anaderi
Copy link
Author

anaderi commented Jul 30, 2020

anyone?

@jameschch
Copy link
Owner

Unfortunately the python runtime does not expose much useful information. It is possible to recover more for debugging if compiled from source. I have seen this error when the build is setup differently than as stated in the readme, so perhaps check your x86/x64 target flag. It might also help to do a clean before building.

You may also get this error if trying to run a Python algorithm multi threaded or with the wrong runner, however the optimizer code should prevent this. Can you supply the optimization.config you used for the python algorithm?

There is a Python algorithm integration test, so it may be interesting if you can run this.

Beyond these checks it will help if you can describe your system OS, .net framework or mono version and any other relevant details as well as supplying the log.txt and error.txt.

@AmazingAbhi
Copy link

I am facing the same issue wherein the Python version gets stuck at PythonEngine.Initialize():

  1. Building on x86
  2. Windows 10
  3. Visual Studio 2019
  4. Python 3.6.8

Getting no error on VB output but following warning:

image

Following is the code for optimization.json:

{ "genes": [ { "key": "take", "min": 0.02, "max": 0.1, "precision": 2, "actual": 0.06 }, { "key": "fast", "min": 6, "max": 48, "precision": 0, "actual": 44 }, { "key": "slow", "min": 48, "max": 500, "actual": 63 } ], "populationSize": 24, "populationSizeMaximum": 48, "generations": 20, "stagnationGenerations": 30, "maxThreads": 1, "configPath": "../../../../Lean/Launcher/config.json", //"configPath": "C:/Users/Abhishek/source/repos/Lean/Launcher/config.json", "algorithmTypeName": "ParameterizedSharedAppDomainAlgorithm", //"algorithmLocation": "Jtc.Optimization.LeanOptimizer.Example.dll", "algorithmLocation": "../../../Jtc.Optimization.LeanOptimizer.Example/ParameterizedSharedAppDomainAlgorithm.py", //"algorithmLanguage": "CSharp", "algorithmLanguage": "Python", "includeNegativeReturn": true, "onePointCrossover": true, "fitnessTypeName": "Jtc.Optimization.LeanOptimizer.OptimizerFitness", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.ConfiguredFitness", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.NFoldCrossReturnMaximizer", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.NFoldCrossSharpeMaximizer", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.SharpeMaximizer", "useSharedAppDomain": false, "enableRunningDuplicateParameters": false, "dataFolder": "../../../../Lean/Data", "minimumTrades": 1, "enableFitnessFilter": true //"startDate": "2013-10-08T00:00:00Z", //"endDate": "2013-10-10T00:00:00Z", //"mutationProbability": 0.5, //"crossoverProbability": 0.75 //"fitness": { // "folds": 2, // "scale": 1, // "modifier": -1, // "resultKey": "Beta", // "name": "MinimizeBeta", // "OptimizerTypeName": "ParticleSwarm" // "OptimizerTypeName": "RandomSearch" // "OptimizerTypeName": "GlobalizedBoundedNelderMead" //} }

Windows

@dakr001
Copy link

dakr001 commented Sep 7, 2020

Hi,

Has there been any progress with this. I haven't really managed to get anything to work. The previous version had issues with dll, and was hoping the latest release will work with python.

Thanks.

@iSevenDays
Copy link

iSevenDays commented Mar 6, 2021

I got everything launching except the final issue - parameterized setup.
в QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) в Z:\Users\seven\projects\algotrading\quantconnect\Lean\Engine\Setup\ConsoleSetupHandler.cs:строка 105 в QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) в Z:\Users\seven\projects\algotrading\quantconnect\Lean\Engine\Engine.cs:строка 117:QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Jtc.Optimization.LeanOptimizer.Example/ParameterizedSharedAppDomainAlgorithm.py. AlgorithmPythonWrapper(): ModuleNotFoundError : No module named 'Jtc' at <module> in ParameterizedSharedAppDomainAlgorithm.py:line 26 :: from Jtc.Optimization.LeanOptimizer.Example import InstancedConfig ModuleNotFoundError : No module named 'Jtc' в QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) в Z:\Users\seven\projects\algotrading\quantconnect\Lean\Engine\Setup\ConsoleSetupHandler.cs:строка 105

My config file
{ "genes": [ { "key": "take", "min": 0.02, "max": 0.1, "precision": 2, "actual": 0.06 }, { "key": "fast", "min": 6, "max": 48, "precision": 0, "actual": 44 }, { "key": "slow", "min": 48, "max": 500, "actual": 63 } ], "populationSize": 24, "populationSizeMaximum": 48, "generations": 20, "stagnationGenerations": 30, "maxThreads": 8, "configPath": "../../../../Lean/Launcher/config.json", //"algorithmTypeName": "ParameterizedAlgorithm", "algorithmTypeName": "ParameterizedSharedAppDomainAlgorithm", //"algorithmLocation": "Jtc.Optimization.LeanOptimizer.Example.dll", "algorithmLocation": "../../../Jtc.Optimization.LeanOptimizer.Example/ParameterizedSharedAppDomainAlgorithm.py", //"algorithmLanguage": "CSharp", "algorithmLanguage": "Python", "includeNegativeReturn": true, "debugging": true, "onePointCrossover": true, "fitnessTypeName": "Jtc.Optimization.LeanOptimizer.OptimizerFitness", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.ConfiguredFitness", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.NFoldCrossReturnMaximizer", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.NFoldCrossSharpeMaximizer", //"fitnessTypeName": "Jtc.Optimization.LeanOptimizer.SharpeMaximizer", "useSharedAppDomain": false, "enableRunningDuplicateParameters": false, "dataFolder": "../../../../Lean/Data", "minimumTrades": 1, "enableFitnessFilter": true //"startDate": "2013-10-08T00:00:00Z", //"endDate": "2013-10-10T00:00:00Z", //"mutationProbability": 0.5, //"crossoverProbability": 0.75 //"fitness": { // "folds": 2, // "scale": 1, // "modifier": -1, // "resultKey": "Beta", // "name": "MinimizeBeta", // "OptimizerTypeName": "ParticleSwarm" // "OptimizerTypeName": "RandomSearch" // "OptimizerTypeName": "GlobalizedBoundedNelderMead" //} }

The must-have fix that I implemented is to fix multi-thread access.
Delete engine.Run(job, algorithmManager, algorithmPath, workerThread);
Add engine.Run(job, algorithmManager, algorithmPath, WorkerThread.Instance);

Also, you need to go to Rapid Environment Editor and make sure there are no invalid paths (displayed in red), if there are some - remove them.
And the last moment - make sure cmd.exe "py" shows Python 3.6.8, not Python 3.7 or other versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants