Comments (7)
Yes, correctly guessed, I was running a "pure" python script from within vscode. And yes, the suggested guard did the trick, whereas both lines are necessary, ``ìf name ...as well as
with ...```.
Thanks a lot!
Perhaps we leave this issue open until I have been able to run the full example?
from ptychography.
Do these two line make problems, when included in a notebook run script?
Yes, because you can't really have a with
-statement that wraps all the notebook cells. The with
statement could be replaced with a ctx.close()
at the end, but that is also inconvenient for users that just "run all cells" and want to keep experimenting in the notebook afterwards.
Wrapping all cells into an if __name__ == "__main__"
has similar problems. I think it would be best to include a non-executing code snippet in a markdown cell, like the one in my comment above.
from ptychography.
Thanks for the report! Does this happen when running a "plain" Python script, or from some kind of REPL (ipython or similar)?
When using a plain Python script, you need to guard the Context
creation, like this:
import libertem.api as lt
if __name__ == "__main__":
with lt.Context() as ctx:
ds = ctx.load("...") # etc.
I suspect this is what's happening here. See also the basic example in the LiberTEM docs
from ptychography.
Perhaps we leave this issue open until I have been able to run the full example?
Sure, sounds good! Maybe we should include a pointer to the documentation in our notebooks, too.
from ptychography.
from ptychography.
from ptychography.
@w-markus yes, using notebooks requires some discipline. The slides show some nice "don'ts". Before sharing a notebook I always restart kernel, run all cells, save and shut down. That pretty much avoids the problem.
In particular for large data analysis they are pretty great, they are my preferred prototyping method. Importing everything, starting up a cluster, warming up the workers etc. takes its time. The full notebook also often has a few "number crunching" steps, for example first sum analysis, then COM analysis, then trotter generation, then ptychography. If I want to quickly benchmark some code changes in the ptycho routine, it is just great to
%autoreload
udf = SSB_UDF(...)
%time res = ctx.run_udf(...)
or change a bit of code in the UDF definition in a cell above and just run it, without going through the entire code that leads up to it. The same goes for a quick %lprun ...
to see where that code spends its time etc. And we get our examples with figures and all embedded in our documentation, and they are at the same time runnable!
TL; DR
- Kernel -> Restart and run all
- Save
- File -> Close and Halt
Problem solved!
from ptychography.
Related Issues (20)
- updating EPIE-Alpaka to latest version HOT 1
- test of GPU version for CDI HOT 3
- Alpaka EPIE version HOT 1
- Distributing the software HOT 6
- Poster for Helmholtz Imaging Platform matchmaking workshop HOT 2
- Update the install instructions for the alpaka binding prototype HOT 1
- Missing requriement documentation for the SSB prototype
- Release version 0.1 with SSB and stitching HOT 13
- Rename the source folder? HOT 1
- Documentation update: Instruct users to fork!
- Documentation: instruct users to install LiberTEM ?! HOT 4
- Collect Numba coverage HOT 2
- Tests w/ data access in CI
- Test on Python 3.11 HOT 1
- Compare with other implementation(s)
- Numba code coverage HOT 2
- Link to publications in the docs
- Check meaningful SSB parameters HOT 1
- Update notebook ssb-live-reconstruction.ipynb with new LiberTEM-live API
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 ptychography.