Ask Your Question

patronics's profile - activity

2024-01-06 08:15:26 +0200 received badge  Popular Question (source)
2021-04-01 13:59:52 +0200 received badge  Nice Question (source)
2021-04-01 13:13:53 +0200 received badge  Notable Question (source)
2017-10-05 18:06:52 +0200 received badge  Popular Question (source)
2014-06-29 21:29:01 +0200 received badge  Popular Question (source)
2014-06-29 21:29:01 +0200 received badge  Notable Question (source)
2014-06-29 21:29:01 +0200 received badge  Famous Question (source)
2013-02-14 14:50:51 +0200 received badge  Organizer (source)
2013-02-14 14:50:33 +0200 asked a question Evaluating a symbolic expression for a Graph

I'm able to do this:

sage: f = function('radius', nargs=1, evalf_func=Graph.radius)
sage: f(graphs.HouseGraph())
2

But not this:

sage: var('G')
sage: expr = f(G)
sage: expr.subs(G=graphs.HouseGraph())
...
TypeError: no canonical coercion from <class 'sage.graphs.graph.Graph'> to Symbolic Ring

What am I missing? Is it not possible to use symbolic expressions like this?

2012-08-11 00:25:41 +0200 received badge  Student (source)
2012-08-09 17:16:46 +0200 commented question Sage is not updating modules imported by an attached file

To avoid any comments about not being Pythonic, I'll say that since I drafted this post, I've read up on duck typing and I'm jettisoning all the abstractmethod business.

2012-08-09 16:18:57 +0200 asked a question Sage is not updating modules imported by an attached file

My file structure looks like:

project/
    __init__.py
    project.py
    bounds.py

project.py looks approximately like:

import sys
import os

import bounds

def myfunction(g):
    if has_bound(g):
        ...

def has_bound(g):
    lbound = 1
    for name, obj in inspect.getmembers(bounds, inspect.isclass):
        if obj.__module__ == 'bounds':
            new_bound = obj.bound(g)
            if new_bound > lbound:
                lbound = new_bound
    return lbound

bounds.py:

import abc

class BoundBase(object):
    @staticmethod
    @abc.abstractmethod
    def bound(g):
        return

class SpecificBound(LowerBoundBase):
    @staticmethod
    def bound(g):
        return 5

Now, I start a Sage session in the Terminal and do attach project.py. I can even make changes in project.py and see the results immediately in Sage. The problem is that if I change something in bounds.py, Sage won't pick up on the changes. I've tried combinations of reset(), detach(), attach(), load(), but the only thing that works is quitting Sage completely and restarting it. There must be a better way!

2012-08-09 11:30:21 +0200 received badge  Supporter (source)
2012-08-08 17:17:21 +0200 asked a question Structuring and naming modules

I'm starting a new research project, and I'm confused about the best way to organize everything.

I'll need to write a few functions that compute invariants on Graphs, but the trick is that each function needs to call lots of smaller functions that compute bounds for the invariant, and then choose the min/max of these bounds and return it. I'd like the smaller functions to be "plug and play," so that other people on the project can come up with new bounds computers, drop them in the folder, and have them automatically used.

Currently, my file structure looks like this:

project/
    __init__.py
    project.py
    bounds/
        __init__.py
       boundcomputer1.py
       boundcomputer2.py
       ...

If I start a Sage session and attach project.py, the code seems to work correctly.

If I do sage -t project.py, it complains about not being able to find the bounds module.

Also, how do I get the functions in project.py to show up under a project namespace, so that I can type project.compute_invariant(), where compute_invariant() is a function defined inside project.py?

I'm happy to take any advice on best practice for a project like this.