Giter Club home page Giter Club logo

Comments (7)

w-markus avatar w-markus commented on August 14, 2024 2

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 aswith ...```.

Thanks a lot!

Perhaps we leave this issue open until I have been able to run the full example?

from ptychography.

sk1p avatar sk1p commented on August 14, 2024 1

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.

sk1p avatar sk1p commented on August 14, 2024

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.

sk1p avatar sk1p commented on August 14, 2024

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.

w-markus avatar w-markus commented on August 14, 2024

from ptychography.

w-markus avatar w-markus commented on August 14, 2024

from ptychography.

uellue avatar uellue commented on August 14, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.