I agree. I should also add that nearly every ticket in trac is marked
as major priority. Indeed, there are lots and lots of things to do on
Sage. That's why we really appreciate your help!
> The ticket has a very good (although a bit old now) description of the
> different packages available to deal with units in Python. One of the
> options, was the units package included in Enthought. This had the
> issue of being under refactoring at that time.
> The actual situation seems to be that the Enthought package has not
> been changed (https://svn.enthought.com/enthought/ticket/1524) because
> of some priority issues in that community (very understandable!), but
> another interesting package was born from this Enthought discussion:
> the "quantities" package:
Thanks for tracking this down. I wondered if it would ever get
refactored. What do you think of the Quantities module? I browsed
through the documentation and it looked very interesting. On the plus
side, it's being actively developed now, which I think sets it apart
from any of the other solutions, right?
> As I can see, this has already been mentioned in a comment to our trac
> ticket, but with no response.
> Honestly, I am not able to understand whether this is good enough to
> be included in SAGE, neither I am able of understanding how much
> refactoring this would need to make this compatible to all the
> wonderful symbolic capabilities of SAGE, but nonetheless I think that
> getting something working at least in the numeric domain, could be
> very useful
> With this, I'm not proposing this package over others (for example,
> Unum looks very mature, but outdated), I'm just asking if one of you
> can spend some minutes to review our trac ticket about units of
> measurement (#3852), and to take some other decision about it.
Which package do you prefer? I think at this point, someone needs to
just make a decision with one of the packages and justify it on
sage-devel. Preferably, that person would offer instructions to install
the top one or two (or three?) choices so that people could try them
out. They would probably also give examples of syntax so others could
see (and maybe compare that to the syntax of the other packages).
Installation is easy if you are familiar with the command line. Just do:
$ sage -sh
Then follow whatever instructions the package gives for installation.
That will install the package into Sage's python library.
By the way, fergusnoble on IRC was working on a units package for Sage
a few days ago. Unfortunately, I don't know his email address, but
Nicolas Thiery does.
This was bug #5356; it's been fixed in Sage 3.4. So you could upgrade
to 3.4, or as a workaround you could use
value = int(10)
As far as the Quantities package goes, it seems to be the problems that
we have always seen between numpy and sage types. I'm not quite sure
what is going on. A Quantity is just a subclass of ndarray. Here are a
few lines illustrating the line where the problem occurs. How come, in
the first case, NotImplemented is returned?
sage: import quantities as pq
sage: super(pq.Quantity, pq.ohm).__mul__(other_sage)
That is what causes the error. However, when we convert the numpy array
representing other to a python integer array, we get something that we
sage: super(pq.Quantity, pq.ohm).__mul__(other_sage.astype(int))
Without the supers above, these two examples are:
sage: import numpy
Does anyone know what is going on here? I'm not sure where the source
of numpy.ndarray.__mul__ is.
> It sounds like the problems is the known issue that numpy does not
> interact very well with Sage data types. Try this:
> from numpy import *
> import quantities as pq
> res = 10r*pq.ohm
> The 10r means to create a python integer, rather than a Sage integer.
> It sounds like there could/should be a small change in quantities made
> to support Sage datatypes. My guess is that it would take just a few
+1 It'd be cool if one could do arbitrary Sage types (not just
floating point numbers). For example
sage: (x * feet).lock('inches')
At least rationals would be nice.
Well, I can at least answer this question. When you type at the sage:
prompt, or in the notebook, the input is run through the "preparser";
this transforms the input from Sage's extended Python syntax into
You can see what it does using the preparse function:
Not necessarily. As I understand it, quantities are just numpy arrays,
basically. Those numpy arrays should be able to contain and deal with
any type (sage or python or whatever).
I tracked down where the error was in what you posted before. I think
if we could get the following two expressions to return the same thing,
we may be good to go. Does anyone know what is going on here?
sage: import quantities as pq
sage: import numpy
Have you asked the Quantities developers to look at this thread? My
guess is that they would be very interested in having Quantities
integrated in with Sage, as it immediately gives them a far greater user
base and exposure (and bug reports!) than otherwise. Besides, they
would probably be better able to work on this than most other people.
> On Mar 20, 10:31 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
>> Maurizio wrote:
>>> Not yet... I think I was previously asking whether some of you guys
>>> are interested in trying to contact them, if you do think it does
>>> makes sense.
>>> I mean, if this community is interested in having this feature, the
>>> Quantities developers are going to find some good feedback,
>>> we could just probably end up losing a good occasion, because things
>>> are not ready yet (although I hope that's not the case)!
>> I think there are a good number of people now that would like to have
>> the feature, and as you well know, there are lots and *lots* of
>> users that would like to have the functionality.
>> I'd say it's time to contact them and see if they can help. If there
>> needs to be changes made to Quantities, then making them now,
>> while it
>> is still solidifying, would be advantageous.
> Hello, I am Darren Dale, the developer of Quantities. Thank you
> Maurizio for contacting me.
Glad to hear from you.
> I guess the question I have for this list is, what would be required
> for quantities to work in sage? I would prefer to try to work out the
> numpy issues I alluded to before quantities gets too much exposure, in
> case changes in API are required (unlikely).
Am I correct in understanding that the values in Quantities all need
to be NumPy values? If this is the case, it probably boils down to
NumPy's not handling of non-Python types. This really needs to get
Not that I'm aware of. As far as I can tell, the root of the problem
boils down to what was explained in
Do you know what is going on (why a "NotImplemented" is returned)? Or
more importantly, do you know if that is something that we need to
implement, or something that numpy needs to implement?
If you don't know the answer off the top of your head, I agree that
posting to the numpy list is the best thing.