WeBWorK Main Forum

using webwork 2.8 with sagecell: problem with acceptance of tos

using webwork 2.8 with sagecell: problem with acceptance of tos

by Marc BUFFAT -
Number of replies: 5
Hello
I have a working webwork 2.8 together with a sagecell server, and I want to use sagecell within webwork problem as described in the WIKI
http://webwork.maa.org/wiki/AskSag
However using the example, I got an error relating to the acknowledge of acceptance of the terms of service for the sagecell server.
The error message is the following
  • Error in asking Sage to do something: When evaluating code, you must acknowledge your acceptance
  • of the terms of service at /static/tos.html by passing the parameter or cookie
  • accepted_tos=true
How can I do it within a webwork problem using AskSage ?
Thanks,

Marc
In reply to Marc BUFFAT

Re: using webwork 2.8 with sagecell: problem with acceptance of tos

by Jason Aubrey -
It's great that you're using this. For reference I'm adding the link to the answers given on the sage-support mailing list:

https://groups.google.com/forum/#!topic/sage-support/OmItSx7zeqk

If you come up with cool webwork problems using AskSage, we would love to see examples.

Thanks,
Jason
In reply to Jason Aubrey

Re: using webwork 2.8 with sagecell: problem with acceptance of tos

by Marc BUFFAT -
Hello Jason,

thanks for your reply,
Now I am able to run the Wiki example using sagecell with the following syntax:
$sageReply1 = AskSage($SageCode1 , {accepted_tos=>true});
which uses the default sagecell server at sagemath.org
However if I want to specify the url of the sagecell server
$sageReply2 = AskSage($SageCode2 , {url=>'http://sagecell.sagemath.org',accepted_tos=>true});
I got an error
Unable to make a sage call to http://sagecell.sagemath

Looking at the source code, I found that the url of the sagecell server must be written as:
$sageReply2 = AskSage($SageCode2 , {url=>'https://sagecell.sagemath.org/service',accepted_tos=>true});

However I want to use my own sagecell server for efficiency reason. The sage server is running as a non-root user using the port 8080:
Accessing my sageserver using
http//sagecellmeca.univ-lyon1.fr:8080
works without problem inside a browser or in moodle, but with AskSage
$sageReply2 = AskSage($SageCode2 , {url=>'http://sagecellmeca.univ-lyon1.fr:8080',accepted_tos=>true});
I got the following error
  • ERROR in contacting sage server. Did you accept the terms of service by
  • setting {accepted_tos=>'true'} in the askSage options?
  • <html><title>405: Method Not Allowed</title><body>405: Method Not Allowed</body></html>
  • IO.pm: ERROR trapped during JSON call to sage:
  • Unable to make a sage call to http://sagecellmeca.univ-lyon1.fr:8080. at [PG]/lib/WeBWorK/PG/IO.pm line 310
using http://sagecellmeca.univ-lyon1.fr/service:8080 does not work either.

Do I need a special configuration of the sagecell server in order to use AskSage inside Webwork ?

I have also try the macro Sage in PG/macro described here in the wiki
http://webwork.maa.org/wiki/Sage_in_WeBWorK

Using the macro in a WebWork problem
Sage(
SageCode=>$SageCode,
AutoEvaluateCell=>'true',
CellServer=>"http://sagecellmeca.univ-lyon1.fr:8080",
);
works, but the interaction with webwork is not so easy as AskSage

Thanks
Marc

In reply to Marc BUFFAT

Re: using webwork 2.8 with sagecell: problem with acceptance of tos

by Jason Aubrey -
Hi Marc,

With respect to AskSage, the url

http://sagecellmeca.univ-lyon1.fr:8080/service

is the correct syntax for specifying your sage-cell webservice on port 8080. I was able to get the wiki example to work using

$sageReply1 = AskSage($SageCode1 , {url=>'http://sagecellmeca.univ-lyon1.fr:8080/service',accepted_tos=>true});

$sageReply2 = AskSage($SageCode2 , {url=>'http://sagecellmeca.univ-lyon1.fr:8080/service',accepted_tos=>true});

In particular, you do not need a special configuration of the sagecell server to use AskSage inside webwork.

However, it might be a good idea to set up a firewall to only allow queries to the service from your webwork server. I mention this because I'm vaugely worried that under load responses from the sage-cell server may not get back to webwork fast enough for the problem to be processed.

We would be very happy if could please update us on how AskSage() is working for you, and especially keep us informed of any problems that arise or features that would be helpful.

Regarding the other macro, Sage(), for displaying interacts in problems - can you be more specific about what you mean by 'the interaction with webwork is not so easy'?

Thanks again!
Jason
In reply to Jason Aubrey

Re: using webwork 2.8 with sagecell: problem with acceptance of tos

by Marc BUFFAT -
Hi Jason
thanks,
the following url is working for me
http://sagecellmeca.univ-lyon1.fr:8080/service
(I had checked the wrong url http://sagecellmeca.univ-lyon1.fr/service:8080)
The webwork and sage server are actually virtual machine for testing, but I will follow our suggestion to setup a firewall.
Concerning the sage macro, I wanted to get the value computed from the sageserver as the correct response for the webwork problem, and not an answer of the problem that will be checked by webwork , as it is used in the wiki example.
But I think I had to used AskSage to do it, and I will try it.

One question: concerning sagecell at sagemath, what hardware configuration
are you using to run the sageserver ?

Thanks again
Marc
In reply to Marc BUFFAT

Re: using webwork 2.8 with sagecell: problem with acceptance of tos

by Marc BUFFAT -
HI Jason
i try another example using AskSage, but I got an error
|Matrices must have at least one entry at line 41 of (eval 14775)
line $ans = Matrix($reply->{'diff'});
apparently I cannot get the sage result using WEBWORK dictionary (hash perl)
here is the code (found in your github)

## Template for calling Sage from within a WebWork pg file
## BEGIN_DESCRIPTION
## Sample problem embedding Sage in WW
## END_DESCRIPTION

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);

###############################################
##
## pg initializations and regular WeBWorK code


Context("Matrix");
Context()->variables->add(u => 'Real');
Context()->variables->add(v => 'Real');

$SageCode1=<<END;
def ff():
return choice([sin,cos,exp,ln,lambda x: x])
def combination(*args):
return prod([choice(i) for i in args])
u,v=var('u v')
def simple_expression():
return combination(range(1,10),[u,u^2],[v,v^2])
def random_expression():
return ff()(simple_expression())+ff()(simple_expression())
f(u,v)=(random_expression(),random_expression(),simple_expression())
WEBWORK['function']=f(u,v)
WEBWORK['diff']=f.diff()(u,v)
END

# Sage
$reply = AskSage($SageCode1,{seed=>$problemSeed, accepted_tos=>true});

$F = Formula($reply->{function});
$ans = Matrix($reply->{'diff'});

Context()->texStrings;
BEGIN_TEXT
Find the total derivative \(Df\) of \[f(u,v)={$F}\]
\{ $ans->ans_array(50)\}
END_TEXT

Context()->normalStrings;
ANS($ans->cmp());
ENDDOCUMENT();

Any Idea ? Marc