Getting rid of reset() and restore()?

121 views
Skip to first unread message

Jeroen Demeyer

unread,
Sep 19, 2016, 6:49:29 AM9/19/16
to sage-devel
Hello,

is there anybody who uses the functions reset() or restore() from
src/sage/misc/reset.pyx

They are meant to "reset" the global state in the interactive session to
what it was when Sage started up. This seems useless (why not just quit
Sage and restart it?) and dangerous (it resets global variables but not
all other places potentially storing global state).

I should also mention that the implementation of these functions is
quite hacky, relying on Cython's old-style-globals behaviour and using
the magic sage_mode variable (set on Sage startup).

I would prefer to remove these functions (after a deprecation period
obviously). Thoughts?


Jeroen.

Thierry

unread,
Sep 19, 2016, 7:12:45 AM9/19/16
to sage-...@googlegroups.com
Hi,

On Mon, Sep 19, 2016 at 12:49:27PM +0200, Jeroen Demeyer wrote:
> Hello,
>
> is there anybody who uses the functions reset() or restore() from
> src/sage/misc/reset.pyx


Various users are frequently asking for this, see e.g. this 3-hours-old
question on ask:
https://ask.sagemath.org/question/34855/how-to-kill-a-variable/

Ciao,
Thierry






> They are meant to "reset" the global state in the interactive session to
> what it was when Sage started up. This seems useless (why not just quit Sage
> and restart it?) and dangerous (it resets global variables but not all other
> places potentially storing global state).
>
> I should also mention that the implementation of these functions is quite
> hacky, relying on Cython's old-style-globals behaviour and using the magic
> sage_mode variable (set on Sage startup).
>
> I would prefer to remove these functions (after a deprecation period
> obviously). Thoughts?
>
>
> Jeroen.
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To post to this group, send email to sage-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

Vincent Delecroix

unread,
Sep 19, 2016, 7:22:42 AM9/19/16
to sage-devel
n 19 September 2016 at 13:12, Thierry <sage-goo...@lma.metelu.net> wrote:
> Hi,
>
> On Mon, Sep 19, 2016 at 12:49:27PM +0200, Jeroen Demeyer wrote:
>> Hello,
>>
>> is there anybody who uses the functions reset() or restore() from
>> src/sage/misc/reset.pyx
>
>
> Various users are frequently asking for this, see e.g. this 3-hours-old
> question on ask:
> https://ask.sagemath.org/question/34855/how-to-kill-a-variable/

The answer to that question is wrong. You should use Python "del f" to
kill the variable f.

Vincent

Martin R

unread,
Sep 19, 2016, 9:55:03 AM9/19/16
to sage-devel
I use it all the time, mainly for "x", "n", and "pi":

sage: n = 5
sage: del n
sage: n
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-fe13119fb084> in <module>()
----> 1 n

NameError: name 'n' is not defined
sage: reset("n")
sage: n
<function numerical_approx at 0x7f86c46dc0c8>

Jeroen Demeyer

unread,
Sep 19, 2016, 9:58:25 AM9/19/16
to sage-...@googlegroups.com
On 2016-09-19 15:55, 'Martin R' via sage-devel wrote:
> I use it all the time, mainly for "x", "n", and "pi":

But never reset() without arguments?

Martin R

unread,
Sep 19, 2016, 10:27:36 AM9/19/16
to sage-devel
right.

William Stein

unread,
Sep 19, 2016, 12:51:21 PM9/19/16
to sage-devel
On Mon, Sep 19, 2016 at 3:49 AM, Jeroen Demeyer <jdem...@cage.ugent.be> wrote:
Hello,

is there anybody who uses the functions reset() or restore() from src/sage/misc/reset.pyx

They are meant to "reset" the global state in the interactive session to what it was when Sage started up. This seems useless (why not just quit Sage and restart it?)

It's orders of magnitude faster than doing that.
 
and dangerous (it resets global variables but not all other places potentially storing global state).

That's only "dangerous" if you expect reset to do the same thing as restart sage, which is not what it does.
 

I should also mention that the implementation of these functions is quite hacky, relying on Cython's old-style-globals behaviour and using the magic sage_mode variable (set on Sage startup).

I rewrote both reset and restore for Sage worksheets in SMC


In SMC the interactive worksheet has its own dict and has to manage it itself.  Hence the old-style Cython stuff isn't needed or useful.
 
I would prefer to remove these functions (after a deprecation period obviously). Thoughts?

They are re-implemented in SMC sage worksheets, so if you remove them from the Sage command line and jupyter, it will make things even less compatible.

William
 



Jeroen.

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscribe@googlegroups.com.

To post to this group, send email to sage-...@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.



--

Jeroen Demeyer

unread,
Sep 19, 2016, 12:56:02 PM9/19/16
to sage-...@googlegroups.com
On 2016-09-19 18:50, William Stein wrote:
> That's only "dangerous" if you expect reset to do the same thing as
> restart sage

I would guess that users *do* expect that.

William Stein

unread,
Sep 19, 2016, 1:04:25 PM9/19/16
to sage-devel
sage: reset?
Docstring:
   Delete all user-defined variables, reset all global variables back
   to their default states, and reset all interfaces to other computer
   algebra systems.
 
   If vars is specified, just restore the value of vars and leave all
   other variables alone (i.e., call restore).
 
   Note that the variables in the set sage.misc.reset.EXCLUDE are
   excluded from being reset.
 

That doesn't suggest reset does the exact same thing as restarting Sage.


--

Dima Pasechnik

unread,
Sep 23, 2016, 5:08:54 AM9/23/16
to sage-devel
various CASs have similar facilities, e.g. Maple has "restart" which is not a complete restart from scratch.
Thus users won't always expect reset to be as disruptive is a complete restart from scratch.
 
Reply all
Reply to author
Forward
0 new messages