Commit Graph

64 Commits

Author SHA1 Message Date
michael-sena f2fc1aae9e Append the full stacktrace to the algorithm loading exception message. (#4775)
* Append the full stacktrace to the algorithm loading exception message.

* Remove exception message loader duplication

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-09-30 12:42:21 -03:00
AlexCatarino c7804423f7 Mute Python Library Warning Logging
Adds `logging.captureWarnings(True)`
2019-08-27 20:39:20 +01:00
Martin-Molinero 92cc56e2d9 Merge pull request #3376 from IlshatGaripov/loader-type-load-catch-improvement
ReflectionTypeLoadException exception handling improvement.
2019-08-15 17:09:56 -03:00
Martin Molinero f887c42638 Enable python and CSharp debugging
- Adding `DebuggerHelper` class, handles debugging initialization
- Setting the "PYTHONPATH" will be handled by the `JobQueue`
2019-08-12 22:03:13 -03:00
Jared 992d721d08 Revert "Reduce python load time 30% (#3440)" (#3441)
Reverts test commit 70017f0e05.
2019-07-28 18:37:34 -07:00
Jared 70017f0e05 Reduce python load time 30% (#3440)
Optimize python load times
2019-07-28 17:20:52 -07:00
IlshatGaripov 79a4e6a8df Uses LoaderExceptions.Length to count null entries. 2019-07-15 16:42:21 +00:00
IlshatGaripov 191f097492 Adds log for count of the null entries 2019-07-15 16:14:39 +00:00
IlshatGaripov 24c3efed36 ReflectionTypeLoadException exception handling improvement.
Removing always false if statement.
2019-07-09 10:49:20 +00:00
Gerardo Salazar 0ea16eb53b Fix bad env var from being created when PYTHONPATH is empty 2019-07-01 17:34:02 -07:00
Martin Molinero 4382aa1886 Add algorithm thread
- Adding `WorkerThread` class, wrapper for a worker thread that will
execute given `Actions`.
    - Algorithm related code (`Construction`, `Initialization`,
    `Execution` will be executed by the same `WorkerThread` instance,
    this is required for `Python` debugging.
2019-05-09 11:23:28 -03:00
Martin Molinero 8ac4b37e5f Load algorithm faster
- Make `Isolator.ExecuteWithTimeLimit()` sleep interval configurable.
- `Loader` will now use 50ms
2018-10-18 20:08:25 -03:00
Stefano Raggi 5c9b81cef1 Fix Python initialization and imports for multiple tests 2018-10-02 20:28:13 +02:00
mblouin02 c39537e24d Fix loader error message when algorithm not found
When the algorithm type in config.json was not found, Loader.cs
would throw a confusing error message. Modified the error message
to make it clearer.

Previous error message: "Unable to resolve multiple algorithm types
to a single type...". New error message: "Algorithm type name not
found,or unable to resolve multiple algorithm types to a single type...".
2018-07-04 23:31:05 -04:00
Stefano Raggi 76586717cb Enable running multiple Python regression algorithms together
Previously when running two or more Python algorithms, the second test was crashing with a Python Fatal Error.
2018-07-03 20:51:29 +02:00
AlexCatarino e9899e357d Improves Exception Messaging For Loader
Improves the message when the Loader cannot resolve the algorithm to load. It happens when the assemblies don't have a QCAlgorithm class that match the algorithm name or you have 2-of them so Lean doesn't know which one to backtest.

The possible Loader exceptions are thrown as `AlgorithmSetupException` to mach the pattern for exceptions during initialization.
2018-06-28 13:27:08 +01:00
AlexCatarino 9705c8d4d1 Fixes python path order
The first place python should look for scripts is not the current directory, but the directory defined at "algorithm-location".
2018-04-19 11:35:42 +01:00
AlexCatarino 36abacce11 Ensure full directory paths 2018-04-18 11:46:13 +01:00
AlexCatarino b8ea13be2a Adds more locations to PYTHONPATH
Before loading python algorithms, set `PYTHONPATH` with `CurrentDirectory`, algorithm location and current/environment `PYTHONPATH`.
2018-04-17 22:31:48 +01:00
AlexCatarino 4e3577939d Refactors AlgorithmPythonWrapper
Move the logic of importing the module into AlgorithmPythonWrapper where it is wrapped.
Throws an exception if the script does not have a class that inherits from either QCAlgorithm not QCAlgorithmFramework.
Adds a check for OnData being defined in the module. If not, OnData from the base class will not be called (it causes stack overflow otherwise)
2018-03-12 23:36:39 +00:00
AlexCatarino 5d82c32040 Removes the abstract classifier of QCAlgorithmFramework
This change is required because pythonnet cannot initialize abstract types. Loader.cs was modified to avoid loading QCAlgorithmFramework type.
2018-03-12 22:42:42 +00:00
AlexCatarino cd1d45ccf0 Minor fixes
Use interpreter.GetMessageHeader(e) instead of e.Message to produce to collated exception message containing the messages from inner exceptions.
Add the DllNotFoundPythonExceptionInterpreterTests to the test project.
2018-03-06 11:02:13 +00:00
AlexCatarino 718c1d61c8 Implements DllNotFoundPythonExceptionInterpreter
This exception interpreter interprets a DllNotFoundException that is thrown when pythonnet cannot fing the python dynamic-link library in the system.
2018-03-05 22:55:11 +00:00
AlexCatarino 0f57c2fd43 Fixes Custom Data for Python
In order to access the custom data classes, the module containing them was added to the ObjectActivator. This was unnecessary if it wasn't a custom data algorithm.
Also, this operation would not be taken into account if the custom data class were defined after the algorithm was created: this is the case for QuantBook.
We refactor how custom data is handled: a new class was added to provide a instance creation factory that creates an instance of each python custom type.
2018-03-01 19:28:30 +00:00
Michael Handschuh 18a559943e Upgrade LEAN Python to 3.6 from 2.7
- Adds log to display the python version the algorithm is using.
- Fixes python algorithms that were failing because of small subtleties
like leading zeroes.
- Updates pythonnet with a version compiled with python 3.6 flags

- Changes in DockerfileFoundation: we now use miniconda to manage the python
environment.
- Took the opportunity to add NTLK (#1349), Tensorforce (#1369) and
PyTorch/Pyro (#1385).
- Changes readme in Algorithm.Python to show steps to install miniconda
2018-02-23 15:09:06 -05:00
Stefano Raggi a39e6a8e28 Revert "Merge pull request #1526 from AlexCatarino/python3"
This reverts commit 2e523992d0, reversing
changes made to fa48fc23ea.
2018-02-14 16:03:12 +01:00
AlexCatarino a02553c524 Adds log with python version 2018-02-13 12:57:45 +00:00
Stefano Raggi 9b190f2363 Fix path comparison in Loader
These two path expressions evaluate to the same physical directory, differing only by the trailing separator char:
- new FileInfo(assemblyPath).DirectoryName
- AppDomain.CurrentDomain.BaseDirectory
2017-08-17 22:08:23 +02:00
comesx4 fac89a6fae this judgment should be "!=" if the assembly not located in the base directory 2017-08-17 17:34:17 +08:00
AlexCatarino 919e0225aa Removes Impromptu.ActLike call at the python wrapper
Calling Impromptu.ActLike<IAlgorithm> to make the python object acts like a IAlgorithm caused multiple AlgorithmPythonWrapper objects running in parallel to hold the same python object. That call was removed and instead we access the python object directly.

- Removes AlgorithmPythonUtil.py and add its code directly in AlgorithmPythonWrapper.cs

- Clean up: removes all references to IronPython and ImpromptuInterface
2017-06-02 17:54:54 +01:00
Anshul e7a3a2f3bd Fixes 5 warnings with code CS1574 2017-05-18 17:05:09 +05:30
jaredbroad 469abd42cf Shuffle PyUtil to build-none, common project 2017-04-30 17:44:43 -04:00
jaredbroad 2ac57081a6 Fix static activator reuse and made PyUtils copy to bin directory 2017-04-30 17:17:09 -04:00
jaredbroad b2e8e61187 Copied python module into bin to import 2017-04-30 16:08:15 -04:00
jaredbroad cd56b5323d Tidy up the local loading of pyc files 2017-04-30 13:10:27 -04:00
AlexCatarino 8545f50bc1 TryCreatePythonAlgorithm preference for compiled python
TrtCreatePythonAlgorithm looks for compiled python (*.pyc) before it fetches python scripts (*.py). If we have used the build script, we have the compiled objects and make a faster load.
2017-04-11 12:12:57 +01:00
jaredbroad 0f40b0df05 Merge remote-tracking branch 'origin/master' into pythonnet 2017-03-26 10:14:03 -04:00
jaredbroad fe9a9cc44e Refactor TryCreateAlgorithmInstanceWithIsolator to take job and set ram limit 2017-02-17 09:34:34 -05:00
jaredbroad 19d47a5ddb Explicitly set ram allocation for creating algorithm to 1024mb 2017-02-16 18:20:05 -05:00
AlexCatarino 9774af9adc Custom Data for Python Support 2017-02-09 17:48:50 -02:00
AlexCatarino 914475e26d PythonWrappers namespacing to match the project/directory structure
- PythonWrappers namespacing to match the project/directory structure
- Adds null checks to SetHistoryProvider and SetRunTimeError
2017-01-12 18:12:59 -02:00
AlexCatarino 74194d6aca Few tweaks:
- Uses QuantConnect.pythonnet nuget pachage
- Python file location loaded from config
- Remove unnecessary if-null in QCAlgorithm's SetHistoryProvider and SetRunTimeError
2017-01-12 14:21:39 -02:00
AlexCatarino 68fd8a4120 New Python Support Framework
Initial commit
2017-01-10 16:12:19 -02:00
AlexCatarino 51c33f876f User-frieldly warning about algorithm name
Fixes warning message.
Ref.: issue #456 and #476
2016-07-12 19:21:30 -03:00
AlexCatarino 648e4b1c7d User-frieldly warning misspecification of algorithm name
Defines a new resolver function to return null instead of throwing so that Loader can return a user-friedly error message.
2016-07-11 10:56:32 -03:00
jaredbroad aed21365f5 Fixed issue when no python algorithm name given 2016-06-28 14:07:10 -04:00
AlexCatarino a3ddbb8a55 Python algos in a file with the algo name like C#
build.bat (batch.sh in Linux) includes the code inside the file with the desired algorithm (set in config.json by "algorithm-type-name") in the python DLL (QuantConnect.Algorithm.Python.dll) via IronPython.
In the AlgorithmFactory,  Loader.TryCreatePythonAlgorithm imports the module with the algorithm name instead of "main".

Closes #289
2016-02-15 17:21:18 -05:00
Michael Handschuh 2e62007876 Removes unused methods from Loader 2016-01-19 17:57:07 -05:00
snugs be950e756a Log full errors/stack traces
Many places in the code used Log.Error(err.Message) or equivalent which
strips out all the really useful information, such as the stack trace
and inner exceptions. Using Log.Error(exception) is the correct way to
log an error as it will correctly write all the message details, also,
by passing the full Exception object we can improve the logging in this
one place and all call sites will automatically benefit from the improvements
2015-12-02 12:35:33 -05:00
snugs e1938baafe Clean up using directives 2015-09-01 22:17:35 -04:00