Comments (3)
@t-wolfeadam I just figured this out. I did exactly what you put here. I didn't know that pickle saved the path to the module used.
There's that, but still the issue of a discrepancy between loading from the active environment in an interactive shell (which works) versus when called via Pypeline (which does not) when the idea is that they should behave the same.
After looking into it more, the way Pypeline creates the Python environment causes __name__
to be set to "builtins" (vs "__main__"
in an interactive shell). The same thing happens to PyCharm's shell (SO ref) - something for me to look into at some point
from anylogic-pypeline.
Interesting use case!
Is there a limitation with "where" on my computer pypeline actually runs?
I thought the answer was "no": before this problem, I would've touted that it runs the same way as if you execute a script or use in an interactive terminal relative to the model's directory. Turns out pickling is an exception!
To test this, I started by creating a setup (assumingly) similar to yours (see here) and generated the pkl object from running the shown script directly.
I then added a 'helper' script in the model directory for streamlining the python code needed in AL and for testing outside of AL (see here) - as you can see, running that directly does work. However, if I try importing the helper from a separate interactive terminal, it fails for a similar reason it does in AL (see here). Double however, the successful "direct loading" seen in the screenshot fails when using Pypeline -- that, I don't know why.
I did find a workaround though: you just need a custom unpickler that redirects the class lookup to the correct module. Updating the 'helper.py' script to look like the following allows it to work from anywhere.
class MyCustomUnpickler(pickle.Unpickler):
def find_class(self, module, name):
if module == "__main__":
module = "pickler" # script name that generated the file
return super().find_class(module, name)
def get_obj():
with open("python_files/pickling_test/pickled_object.pkl", "rb") as f:
unpickler = MyCustomUnpickler(f)
obj = unpickler.load()
return obj
In case you want to explore yourself: Model323.zip
from anylogic-pypeline.
@t-wolfeadam I just figured this out. I did exactly what you put here. I didn't know that pickle saved the path to the module used.
from anylogic-pypeline.
Related Issues (20)
- Missing user guide HOT 2
- Reinforcement learning HOT 5
- fromJson for an int[][] HOT 2
- Agent population to json issue HOT 2
- Pycommunicator not dragging onto the experiment page in anylogic HOT 2
- Reinforcment Learning HOT 1
- Error with setting up python subprocess (Macbook) HOT 2
- Encoding error when trying to save a file on Windows HOT 1
- Python files missing HOT 1
- Issues with Python on Mac HOT 2
- "Run and Runresults are not defined" problem HOT 4
- Issue with reflectiveObjects HOT 2
- No able to open the model examples HOT 1
- Bug with Mac HOT 6
- Issue with AnyLogic 8.8.2 HOT 1
- Run Python scripts before each experiment run HOT 6
- jsonifier library error HOT 4
- Error during model creation in AnyLogic HOT 3
- Pypeline and AnyLogic Cloud HOT 3
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 anylogic-pypeline.