Comments (5)
Thanks for this @Andrew-S-Rosen ideally it should be so that all kwargs of electrons are properties as well that can be set post creation. I will update the issue as a bug/feature-enhancement as well.
Cc: @kessler-frost / @jimmylism
from covalent.
CC: @cjao , any quick idea on why this would be the case for packages?
from covalent.
@Andrew-S-Rosen I think this may be due to how the objects are imported: https://stackoverflow.com/a/3536638
from covalent.
@Andrew-S-Rosen This is a fun question and boils down to how cloudpickle (Covalent's serialization mechanism) works. The key difference between your examples
(1) non-working
import covalent as ct
from mypackage import increment, subflow
@ct.lattice
def workflow(x, op):
return subflow(x, op)
increment.electron_object.executor = "local"
ct.dispatch(workflow)(1, increment)
(2) working
import covalent as ct
from mypackage import increment
@ct.lattice
def workflow(x, op):
return op(x)
increment.electron_object.executor = "local"
ct.dispatch(workflow)(1, increment)
is that (1) pickles the wrapped increment
function -- as a parameter of the sub_workflow
electron -- whereas in (2) only the underlying function is serialized, not the electron_object
attribute. Because increment
lives in an external module instead of __main__
, Cloudpickle will serialize it by reference, not by value. Thus when the increment
electron is unpickled in the executor that builds out sub_workflow
, its attributes -- such as electron_object
-- are whatever they are defined to be in mypackage.py
.
Example:
mypackage.py
class Electron:
def __init__(self):
self.executor = "dask"
def my_func():
pass
my_func.electron_object = Electron()
main.py
import cloudpickle
import mypackage
mypackage.my_func.electron_object.executor = "local"
with open("my_func.pkl", "wb") as f:
cloudpickle.dump(mypackage.my_func, f)
exec.py
import pickle
with open("my_func.pkl", "rb") as f:
my_func = pickle.load(f)
print(my_func.electron_object.executor)
casey@AgnostiqHQ tests$ python main.py && python exec.py
dask
But now if we instruct cloudpickle to serialize the mypackage
module by value:
main.py
import cloudpickle
import mypackage
mypackage.my_func.electron_object.executor = "local"
cloudpickle.register_pickle_by_value(mypackage)
with open("my_func.pkl", "wb") as f:
cloudpickle.dump(mypackage.my_func, f)
we get
casey@AgnostiqHQ tests$ python main.py && python exec.py
local
from covalent.
@wjcunningham7, @cjao: Thank you both for the very insightful replies!
Because increment lives in an external module instead of main, Cloudpickle will serialize it by reference, not by value.
That's the main takeaway for sure. I didn't realize that --- subtle! In any case, this isn't a major issue, but I did want to flag it as a potential "gotcha." With this response, I feel pretty comfortable knowing what's going on now. Feel free to close if you wish!
from covalent.
Related Issues (20)
- Remove quantum dependency from SDK only installs HOT 1
- Splitting up nightly and release workflows and possibly fixing the docker workflow as well which pushes the executor base images on AWS
- Looking into the GPU support for GCP Batch executor PR by the external contributor
- Updating/Verifying OS support for python 3.9 and 3.10 HOT 1
- Suppress the SQL Alchemy warning that shows up when starting fresh covalent server
- Address consistent error in logs with no functional effect
- Resolve all the dependabot PRs across all repos
- Deployment CRM does not convert `bool`, `NoneType`, or `Sequence` correctly HOT 1
- Remove electron object from electron decorator wrapper HOT 1
- Unable to emit socket messages for dispatches
- SDK only installs fail due to unsatisfied SQLAlchemy dependency
- Better sublattice graph navigation
- Add support for redispatch tracking original dispatch id to OS HOT 1
- Optimizing `covalent start/stop` time
- A `TypeError` is raised if a dictionary with a non-string key is passed as the input to an `@electron`
- Add a how to for module deps feature
- Logs in the UI have the wrong timezone
- The `workdir` setting does not appear to work for the Dask/local executors
- Editing the `@ct.lattice` executor in a Jupyter Notebook is not always reflected if importing a `@ct.electron`
- Updating the compatibility matrix doc
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 covalent.