Salvando sessões/save_session.sagews

AuthorLeon Denis
Date2017-01-06T15:42:53
Project195a1c48-6eb8-40e9-a2c3-109d9f642aff
LocationSalvando sessões/save_session.sagews
Original filesave_session.sagews

Exemplificando o salvamento de sessões

b=2*2.7
def soma():    s=0    for i in [1..1000]:        s+=i    return s
a=soma()
y=var('y'); f=x^2+y^2
n(sqrt(log(2^13 + 1))/factorial(20))
1.23385103941001e-18
save_session('teste')
save_session?
File: /projects/sage/sage-7.3/src/sage/misc/session.pyx
Signature : save_session(name='sage_session', verbose=False)
Docstring :
Save all variables that can be saved to the given filename.  The
variables will be saved to a dictionary, which can be loaded using
"load(name)" or "load_session()".

Note:

  1. Function and anything else that can't be pickled is not
     saved. This failure is silent unless you set "verbose=True".

  2. In the Sage notebook the session is saved both to the
     current working cell and to the "DATA" directory.

  3. One can still make sessions that can't be reloaded.  E.g.,
     define a class with:

        class Foo: pass

     and make an instance with:

        f = Foo()

     Then "save_session()" followed by "quit" and "load_session()"
     fails. I doubt there is any good way to deal with this.
     Fortunately, one can simply re-evaluate the code to define
     "Foo", and suddenly "load_session()" works fine.

INPUT:

   * "name" -- string (default: 'sage_session') name of "sobj" to
     save the session to.

   * "verbose" -- bool (default: "False") if "True", print info
     about why certain variables can't be saved.

OUTPUT:

   * Creates a file and returns silently.

EXAMPLES:

For testing, we use a temporary file that will be removed as soon
as Sage is left. Of course, for permanently saving your session,
you should choose a permanent file.

   sage: a = 5
   sage: tmp_f = tmp_filename()
   sage: save_session(tmp_f)
   sage: del a
   sage: load_session(tmp_f)
   sage: print(a)
   5

We illustrate what happens when one of the variables is a function:

   sage: f = lambda x : x^2
   sage: save_session(tmp_f)
   sage: save_session(tmp_f, verbose=True)
   Saving...
   Not saving f: f is a function, method, class or type
   ...

Something similar happens for cython-defined functions:

   sage: g = cython_lambda('double x', 'x*x + 1.5')
   sage: save_session(tmp_f, verbose=True)
   Not saving g: g is a function, method, class or type
   ...