Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple instances of the PariInstance object #21806

Closed
jdemeyer opened this issue Nov 3, 2016 · 37 comments
Closed

Allow multiple instances of the PariInstance object #21806

jdemeyer opened this issue Nov 3, 2016 · 37 comments

Comments

@jdemeyer
Copy link

jdemeyer commented Nov 3, 2016

Since the PariInstance object is really just a callable namespace without state, it should be possible to create multiple instances of it.

The rationale for this is that when multiple python modules depend upon CyPari, each one must instantiate its own PariInstance object, or possibly an object inheriting from it.

Since PariInstance initializes the PARI library upon __init__, we must be careful to do this initialization only once.

When PariInstance.__init__() is called a second time with a size argument which is larger than the current size, we should increase (but never decrease) the PARI stack size but otherwise do nothing.

Depends on #21820

CC: @defeo

Component: interfaces

Keywords: atelierpari2017

Author: Luca De Feo, Jeroen Demeyer

Branch/Commit: b70450d

Reviewer: Vincent Delecroix, Luca De Feo

Issue created by migration from https://trac.sagemath.org/ticket/21806

@jdemeyer jdemeyer added this to the sage-7.5 milestone Nov 3, 2016
@jdemeyer
Copy link
Author

jdemeyer commented Nov 4, 2016

Dependencies: #21820

@defeo
Copy link
Member

defeo commented Jan 9, 2017

@defeo
Copy link
Member

defeo commented Jan 10, 2017

Commit: 061467f

@defeo
Copy link
Member

defeo commented Jan 10, 2017

New commits:

061467fAllow the PariInstance object to be allocated multiple times.

@defeo
Copy link
Member

defeo commented Jan 10, 2017

Author: Luca De Feo

@defeo
Copy link
Member

defeo commented Jan 10, 2017

Changed keywords from none to atelierpari2017

@videlec
Copy link
Contributor

videlec commented Jan 10, 2017

comment:5

I don't understand clearly why we should allow multiple pari instances. Could it be precised in the ticket description? (we discussed it yesterday but I don't quite remember)

@videlec
Copy link
Contributor

videlec commented Jan 10, 2017

comment:6

minor remark: there are trailing whitespaces!

@videlec
Copy link
Contributor

videlec commented Jan 10, 2017

Reviewer: Vincent Delecroix

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

aa6e5ddRemoved trailing withespaces

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2017

Changed commit from 061467f to aa6e5dd

@defeo
Copy link
Member

defeo commented Jan 10, 2017

comment:9

Note that an alternate, reasonable, design would initialize the PARI library at module load, rather than in __init__. However this ticket is not concerned with this.

With the current design, we have the (dubious) advantage of being able to call pari_close() (via PariInstance._close(), and then reinitialize PARI by creating a new PariInstance object at leisure.

@defeo

This comment has been minimized.

@defeo

This comment has been minimized.

@videlec
Copy link
Contributor

videlec commented Jan 10, 2017

comment:11

pari is initialized at module load since a global pari_instance is created! Calling _close is dangerous since this global instance is still accessible... we might want to document this bug-feature

@jdemeyer
Copy link
Author

@jdemeyer
Copy link
Author

Changed commit from aa6e5dd to 9df4382

@jdemeyer
Copy link
Author

Changed author from Luca De Feo to Luca De Feo, Jeroen Demeyer

@jdemeyer
Copy link
Author

comment:13

Replying to @videlec:

pari is initialized at module load since a global pari_instance is created!

But that will change. cypari2 should not do that.


New commits:

9df4382Move initialization of PARI to PariInstance.__cinit__

@jdemeyer jdemeyer modified the milestones: sage-7.5, sage-7.6 Jan 10, 2017
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

c2d09afImprove documentation of _close()

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2017

Changed commit from 9df4382 to c2d09af

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

4b81781Move _close() method right after __init__()

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 10, 2017

Changed commit from c2d09af to 4b81781

@jdemeyer
Copy link
Author

comment:16

New version, needs review...

@defeo
Copy link
Member

defeo commented Jan 10, 2017

@defeo
Copy link
Member

defeo commented Jan 10, 2017

comment:18

All doctests pass, and I like Jeroens modifications.


New commits:

80d4098Typo

@defeo
Copy link
Member

defeo commented Jan 10, 2017

Changed reviewer from Vincent Delecroix to Vincent Delecroix, Luca De Feo

@defeo
Copy link
Member

defeo commented Jan 10, 2017

Changed commit from 4b81781 to 80d4098

@videlec
Copy link
Contributor

videlec commented Jan 11, 2017

comment:19

What should I expect from

sage: from sage.libs.cypari2.pari_instance import PariInstance
sage: p = PariInstance()
sage: p._close()
sage: p('12')

@jdemeyer
Copy link
Author

comment:20

Replying to @videlec:

What should I expect from

sage: from sage.libs.cypari2.pari_instance import PariInstance
sage: p = PariInstance()
sage: p._close()
sage: p('12')

A segmentation fault I guess.

@videlec
Copy link
Contributor

videlec commented Jan 11, 2017

comment:21

Replying to @jdemeyer:

Replying to @videlec:

What should I expect from

sage: from sage.libs.cypari2.pari_instance import PariInstance
sage: p = PariInstance()
sage: p._close()
sage: p('12')

A segmentation fault I guess.

Shouldn't it be documented as I mentioned in [comment:11]?

@jdemeyer
Copy link
Author

comment:22

There is already the comment

            Call this method at you own risk if you really need to free
            the memory used by PARI.

@videlec
Copy link
Contributor

videlec commented Jan 11, 2017

comment:23

Replying to @jdemeyer:

There is already the comment

            Call this method at you own risk if you really need to free
            the memory used by PARI.

This comment is not clear enough. The sentence says that the memory is freed. Not that you will obtain a SEGFAULT if you try to use pari again. Moreover, creating a new pari instance would make pari available again (right?).

@jdemeyer
Copy link
Author

@videlec
Copy link
Contributor

videlec commented Jan 11, 2017

Changed commit from 80d4098 to b70450d

@videlec
Copy link
Contributor

videlec commented Jan 11, 2017

New commits:

b70450dImprove documentation of _close()

@vbraun
Copy link
Member

vbraun commented Jan 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants