question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to run emcee for a fixed amount of time: MemoryError for large nsteps

See original GitHub issue

General information:

  • emcee version: 2.2.1
  • platform: elementary OS 0.4.1 64 bit (based on Ubuntu 16.04)
  • installation method (pip/conda/source/other?): conda

Problem description:

Not really a problem, perhaps a feature request? I’m attempting to set up emcee so that instead of running for nsteps, it runs for a given amount of time. This is a more reasonable approach for me when I have to run my code in a cluster and I have a maximum allocated time I want to take advantage of.

I tried setting a very large number for nsteps (so that emcee would run for and “infinite” amount of time) and then run the sampler inside a for checking if the maximum time has been elapsed. When it has, I break out.

Expected behavior:

I would expect to be able to set a value like nsteps=1000000000 to approximate an “infinite” chain, and then set it loose as described above.

Actual behavior:

I get a MemoryError for nwalkers=200 and nsteps>100000.

What have you tried so far?:

Started with a very large value for nsteps and reduced it until it worked.

Minimal example:

import emcee
import time as t

max_secs = 3600.
nsteps = 100000

nwalkers, ndim, nburn = 200, 6, 500
sampler = emcee.EnsembleSampler(nwalkers, ndim, log_posterior)

# Burn-in
s = t.time()
starting_guesses = random_population()
pos, prob, state = sampler.sample(starting_guesses, iterations=nburn)
elapsed = t.time() - s

s = t.time()
for i, result in enumerate(sampler.sample(pos, lnprob0=prob, rstate0=state, iterations=nsteps)):
    elapsed += t.time() - s
    if elapsed >= max_secs:
        break
    s = t.time()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dfmcommented, Aug 4, 2018

Your issue was that you got a memory error. If you follow the docs that I linked to, you won’t. That’s all. Inside of a sample loop, you can check the time and break out whenever you want.

On Sat, Aug 4, 2018 at 3:53 PM Gabriel Perren notifications@github.com wrote:

I already save the steps manually, I’m not sure what you mean Dan. My goal was: instead of setting a nsteps parameter, set a nhours parameter which would tell emcee for how long to run.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/dfm/emcee/issues/260#issuecomment-410454976, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVYSkS5VszhWXi3VNiANtr-A4LnFC49ks5uNbVjgaJpZM4VWxlP .

– Dan Foreman-Mackey Associate Research Scientist Flatiron Institute http://dfm.io

0reactions
Gabriel-pcommented, Aug 5, 2018

I understand what you meant now, thank you. I guess I could use that to run the sampler in blocks of smaller nsteps saving and loading until the time has run out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Handle the MemoryError in Python - Rollbar
A MemoryError means that the interpreter has run out of memory to allocate to your Python program. This may be due to an...
Read more >
API — emcee 2.2.1 documentation - Read the Docs
An estimate of the autocorrelation time for each parameter (length: dim ). ... only use the first 2^n (for the largest power) entries...
Read more >
python - MemoryError when Using the read() Method in ...
Using TextIOWrapper means obj['Body'] is lazily read and decoded in chunks (of a few KB at a time), and the lines are iterated...
Read more >
Leave a question! - Dr. Joaquin Barroso's Blog
Hello, i am facing one problem related to my calculation. When i upload my input file having B3LYP/6-31G (d) set to gaussian then...
Read more >
Classes — QuTiP 4.7 Documentation
Calculate the expectation value of this operator on the given (time-independent) state at a particular time. This is more efficient than expect(QobjEvo(t), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found