Advanced: Detaching from Run Compute

Setup

Let's first make sure we have the latest version of PHOEBE 2.1 installed. (You can comment out this line if you don't use pip for your installation or don't want to update to the latest release).


In [ ]:
!pip install -I "phoebe>=2.1,<2.2"

As always, let's do imports and initialize a logger and a new Bundle. See Building a System for more details.


In [1]:
%matplotlib inline

In [2]:
import phoebe
from phoebe import u # units
import numpy as np
import matplotlib.pyplot as plt

logger = phoebe.logger()

b = phoebe.default_binary()


/usr/local/lib/python2.7/dist-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)
WARNING: Constant u'Gravitational constant' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING:astropy:Constant u'Gravitational constant' is already has a definition in the u'si' system
WARNING: Constant u'Solar mass' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING:astropy:Constant u'Solar mass' is already has a definition in the u'si' system
WARNING: Constant u'Solar radius' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING:astropy:Constant u'Solar radius' is already has a definition in the u'si' system
WARNING: Constant u'Solar luminosity' is already has a definition in the u'si' system [astropy.constants.constant]
WARNING:astropy:Constant u'Solar luminosity' is already has a definition in the u'si' system
WARNING: developer mode enabled, to disable 'rm ~/.phoebe_devel_enabled' and restart phoebe or phoebe._devel_enabled=False to temporarily disable
/usr/local/lib/python2.7/dist-packages/astropy/units/quantity.py:732: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  return super(Quantity, self).__eq__(other)

Now we'll add datasets


In [3]:
b.add_dataset('lc', times=np.linspace(0,20,501))


Out[3]:
<ParameterSet: 11 parameters | kinds: lc, lc_dep>

Run Compute

Here we just pass detach=True to any run_compute call. We'll immediately be returned to the prompt instead of waiting for the results to complete.


In [4]:
b.run_compute(detach=True, model='mymodel')


WARNING:BUNDLE:detach support is EXPERIMENTAL
Out[4]:
<Parameter: detached_job=unknown | keys: description, value, server_status, location, status_method, retrieve_method, uniqueid>

If we then try to access the model, we see that there is instead a single parameter that is a placeholder - this parameter stores information on how to check the progress of the run_compute job and how to load the resulting model once it's complete


In [5]:
b['mymodel']


Out[5]:
<Parameter: detached_job=unknown | keys: description, value, server_status, location, status_method, retrieve_method, uniqueid>

Re-attaching to a Job

We can check on the job's status


In [6]:
b['mymodel'].status


Out[6]:
'unknown'

If we want, we can even save the Bundle and load it later to retrieve the results. In this case where the job is being run in a different Python thread but on the same machine, you cannot, however, exit Python or restart your machine.

When detaching and running on a server (coming soon), you will then be able to exit your Python session or even open the Bundle on a different machine.


In [7]:
b.save('test_detach.bundle')


Out[7]:
'test_detach.bundle'

In [8]:
b = phoebe.Bundle.open('test_detach.bundle')

In [9]:
b['mymodel'].status


Out[9]:
'unknown'

And at any point we can choose to "re-attach". If the job isn't yet complete, we'll be in a wait loop until it is. Once the job is complete, the new model will be loaded and accessible.


In [10]:
b['mymodel'].attach()


Out[10]:
<ParameterSet: 3 parameters | qualifiers: detached_job, fluxes, times>

In [11]:
b['mymodel']


Out[11]:
<ParameterSet: 3 parameters | qualifiers: detached_job, fluxes, times>

In [12]:
axs, artists = b['mymodel'].plot()