Skip to content

Update the AskSage method.#1399

Open
drgrice1 wants to merge 1 commit into
openwebwork:PG-2.21from
drgrice1:asksage-update
Open

Update the AskSage method.#1399
drgrice1 wants to merge 1 commit into
openwebwork:PG-2.21from
drgrice1:asksage-update

Conversation

@drgrice1

@drgrice1 drgrice1 commented Apr 17, 2026

Copy link
Copy Markdown
Member

The code that is submitted via the AskSage method no longer works with the newer versions of Sage and needs to be updated.

Also the public Sage cell server at https://sagecell.sagemath.org/service no longer accepts public code via its service endpoint. So make the URL for a sagecell server configurable.

Files for building a sagecell server and deploying it via docker have been added in the sagecell-docker directory. Instructions for doing so are in the sagecell-docker/README.md file.

Remove the accepted_tos parameter from the AskSage call. Just add the parameter internally, and stop requiring that the author do so. It is a meaningless gesture to force the author to do so. Furthermore, the docker build is set to not require that parameter.

Also make it so that the AskSage method can be called without passing any arguments, since there are now none that are required.

@Alex-Jordan

Copy link
Copy Markdown
Contributor

I'm following the docker installation instructions. When I get to run the docker container for the first time, I get:

Building Maxima command completion list (this takes
a few seconds only the first time you do it).
To force rebuild later, delete /home/sage/.sage//maxima_commandlist_cache.sobj.

This has been going on for a long time, maybe 10 minutes. Certainly more than a few seconds. Does that sound normal?

@drgrice1

Copy link
Copy Markdown
Member Author

Generally, that sounds right in terms of what you are seeing. The command completion list build will take a few seconds, but then it will just sit there doing nothing. It is now running. Now to test it set up a server to connect to it using the setting added in openwebwork/webwork2#2951. Usually, you will set up the systemctl service to run this docker container.

@Alex-Jordan

Copy link
Copy Markdown
Contributor

When I hit ctrl-C to end, I then see:

^C
Done!

Building R command completion list (this takes
a few seconds only the first time you do it).
To force rebuild later, delete /home/sage/.sage//r_commandlist.sobj.

It seems odd to me that the R command completion list is built after I quit.

@drgrice1

Copy link
Copy Markdown
Member Author

That is what happens for me too. So everything you are seeing is normal. I thing that the output that is shown is actually the result of a job that ran earlier, but the output isn't flushed until you hit Ctrl-C.

@drgrice1

Copy link
Copy Markdown
Member Author

In any case, the AskSage problems work with this.

@Alex-Jordan

Copy link
Copy Markdown
Contributor

This works for me with a minimal problem that uses AskSage. Nice update! Having a local sagecell server running removes a barrier that always kept me from investing in using this.

@Alex-Jordan

Copy link
Copy Markdown
Contributor

My server did not already have docker installed. I'm not sure if that requirement should be mentioned in the release notes or not.

@drgrice1

Copy link
Copy Markdown
Member Author

Using this is optional, but yes, if you want use it you would need to install docker. It would be worth mentioning in the release notes, and adding optional installation instructions to the installation manual.

@pstaabp

pstaabp commented Jun 9, 2026

Copy link
Copy Markdown
Member

I got the docker image up and running. Tested it with a docker exec -it command and entered some sage on the command line and got reasonable response. Pretty sure that is running.

I added the line to localoverrides from the WeBWorK side as is. It looks like it's running on port 3500.

I tried the problem on the wiki: https://wiki.openwebwork.org/wiki/Sage_in_WeBWorK

and just seeing this:

Safari 2026-06-09 13 03 48

I must be missing something...

@drgrice1

drgrice1 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

That isn't an AskSage problem. That problem uses the sage.pl macro for an interactive sage cell. That does not use this at all.

Here is an AskSage problem you can test with:

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Context()->{format}{number} = '%.4f#';

$a = random( 2, 6);
$b = random( 2, 17);
$n = random( 3, 6);
$c = random(-3, 0);
$d = random( 1, 4);

$integrand =
    Formula('sqrt(1 + (' . $a * $n . ' x^' . ($n - 1) . " + $b)^2)")->reduce;

# Use sage to compute the arc length
$sageCode = <<~ "END_CODE";
    x = SR.var('x')
    WEBWORK['arc_length'] = numerical_integral($integrand, $c, $d, eps_abs = 1e-10, eps_rel = 1e-10)[0]
    END_CODE

$sageReply = AskSage($sageCode, { accepted_tos => 'true' });

if (sageReturnedFail($sageReply)) {
    # Fallback value if the sage call fails.
    $arc_length = Compute(0);
} else {
    $arc_length = Compute($sageReply->{webwork}{arc_length});
}

# Main Text
BEGIN_PGML
The length of the curve defined by

[```y = [$a]x^{[$n]} + [$b]x```]

from the point [`([$c], [$a * ($c**$n) + $b * $c])`] to the point
[`([$d], [$a * ($d**$n) + $b * $d])`] is [`[$arc_length->value]`].
END_PGML

ENDDOCUMENT();

@pstaabp

pstaabp commented Jun 9, 2026

Copy link
Copy Markdown
Member

I went back through and wasn't sure I had the port, but now pointing to localhost:3500 (either using curl or a browser) shows it's working.

However running the above problem just times out. I turned on debug, but am seeing anything sage related or why it may not be connecting.

@drgrice1

drgrice1 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

Use the command docker run --rm -p 127.0.0.1:3500:3500 sagecell:latest to run the sage cell server. Also, sometimes you have to wait a bit until the sage cell server is ready. Basically, at least until you see the odd message that @Alex-Jordan saw.

@pstaabp

pstaabp commented Jun 9, 2026

Copy link
Copy Markdown
Member

I'm pretty sure the service is running. Putting localhost:3500 brings up a webpage indicating this is true.

The code that is submitted via the AskSage method no longer works with
the newer versions of Sage and needs to be updated.

Also the public Sage cell server at https://sagecell.sagemath.org/service
no longer accepts public code via its `service` endpoint.  So make the
URL for a sagecell server configurable.

Files for building a sagecell server and deploying it via docker have
been added in the `fsagecell-docker` directory. Instructions for doing
so are in the `sagecell-docker/README.md` file.

Remove the `accepted_tos` parameter from the `AskSage` call.  Just add
the parameter internally, and stop requiring that the author do so.  It
is a meaningless gesture to force the author to do so.  Furthermore, the
docker build is set to not require that parameter.

Also make it so that the `AskSage` method can be called without passing
any arguments, since there are now none that are required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants