More newbie questions... polymake commands in files

Questions and problems about using polymake go here.
gordonfroyle
Posts: 15
Joined: 15 Feb 2011, 08:07

More newbie questions... polymake commands in files

Postby gordonfroyle » 09 Jul 2012, 06:13

Sorry to bombard the list with trivial questions, but once again I have tried to find the answer in the documentation but failed...

I have many polytopes to analyse so I've created a file containing all the necessary polymake commands, thousands of lines of them.

Code: Select all

$ineq = zero_vector(10) | unit_matrix(10); $m0 = new Matrix([[-1,1,1,1,0,1,0,0,1,0,0], [-1,1,1,1,0,0,1,0,0,0,1], [-1,1,1,1,0,0,0,1,0,1,0], .... .... print $p0->VERTICES; .... ....
I just want to execute those commands.

If I am using a package like GAP or Magma or Mathematica and I have a long list of GAP or Magma or Mathematica commands (generated by another program) then I can run them simply by typing (on the command line)

Code: Select all

gap < inputfile magma < inputfile math < inputfile
So I tried "polymake < inputfile" and got "can't start the interactive shell without terminal input".

OK, can I run polymake in "non-interactive" mode? I searched for "interactive" and discovered scripts ...

But I tried loading them by adding "--script" to the command line, or typing script(inputfile) into the interactive shell. Either nothing happens or I get "ERROR: Bareword found where operator expected at input line 1". Even when I deleted everything except a plain Perl statement (print "Success\n";) from the file, I still couldn't read it in.



Is there a way to read in and execute a sequence of commands?

herr
Developer
Posts: 40
Joined: 30 Dec 2010, 13:15

Re: More newbie questions... polymake commands in files

Postby herr » 09 Jul 2012, 09:46

You can use both

Code: Select all

script("scriptfile", arg1, ...);
and

Code: Select all

polymake --script scriptfile ARG1 ARG2
but you have to pay attention to some technical details (like "use application ..." and using "my"). They are explained in the tutorial Scripting. Please feel free to ask again if the tutorial does not help.

paffenholz
Developer
Posts: 212
Joined: 24 Dec 2010, 13:47

Re: More newbie questions... polymake commands in files

Postby paffenholz » 09 Jul 2012, 09:53

Sorry to bombard the list with trivial questions, but once again I have tried to find the answer in the documentation but failed...
Our documentation is not yet really well-structured, we are working on this. As a way around, there is a search box in the top right corner of the documentation page that searches all documentation pages that lists all tutorials/howtos/... that contain your search term. E.g. "Scripting" returns the scripting page.

User avatar
joswig
Main Author
Posts: 282
Joined: 24 Dec 2010, 11:10

Re: More newbie questions... polymake commands in files

Postby joswig » 09 Jul 2012, 09:57

There are several ways to run polymake in a scripted fashion.
  1. Scripts as described above. Observe the slight differences in syntax (as compared to what you just type into the shell).
  2. The

    Code: Select all

    load_command
    function. Reads commands from a file line by line. Needs a <return> after each line; allows command line editing.
  3. As of version 2.12 polymake reads commands from STDIN if called with the option "-" (that is, a single dash, no quotes). Actually,

    Code: Select all

    polymake --help
    tells you.

gordonfroyle
Posts: 15
Joined: 15 Feb 2011, 08:07

Re: More newbie questions... polymake commands in files

Postby gordonfroyle » 09 Jul 2012, 10:15

You can use both

Code: Select all

script("scriptfile", arg1, ...);
and

Code: Select all

polymake --script scriptfile ARG1 ARG2
but you have to pay attention to some technical details (like "use application ..." and using "my"). They are explained in the tutorial Scripting. Please feel free to ask again if the tutorial does not help.
Is there something different about using Mac OS? Because I cannot get any of the command-line versions of these commands to work....

In particular, once I put

Code: Select all

use application 'polytope';
at the beginning of the file and prefix every variable I can see with "my" then loading in a script from within the interactive shell now works. (I had tried the first part when I reached the scripting documentation page, but the rest of that paragraph about lexical scope and so on, did not mean anything to me until I got the hint about using "my".)


However doing

Code: Select all

/Applications/polymake.app/Contents/MacOS/polymake.start --script 13892-poly
or using the single dash for stdin or the "--help" appears to just start up the interactive shell.

(If I use "polymake" rather than "polymake.start" then it creates a new Terminal window, but then the output is just the same.)

paffenholz
Developer
Posts: 212
Joined: 24 Dec 2010, 13:47

Re: More newbie questions... polymake commands in files

Postby paffenholz » 09 Jul 2012, 11:04

Code: Select all

/Applications/polymake.app/Contents/MacOS/polymake.start --script 13892-poly
Indeed, this won't work. MacOS/polymake and MacOS/polymake.start are both Mac-specific scripts that set some environment variables and adjust the path. The actual call to polymake happens inside polymake.start. The bundle was mainly meant for those that want to drag the whole thing to /Applications and then have something to click on, so command line arguments are not handled by the script.

If you want to pass on command line arguments to polymake in this version, then you have to call polymake directly. It is in Resources/polymake/bin/, but you have to set the appropriate library and perl paths first. This basically means executing the export commands you find inside polymake.start prior to calling polymake. The variable $ResourcesDir should point to Resources/

gordonfroyle
Posts: 15
Joined: 15 Feb 2011, 08:07

Re: More newbie questions... polymake commands in files

Postby gordonfroyle » 09 Jul 2012, 14:51

If you want to pass on command line arguments to polymake in this version, then you have to call polymake directly. It is in Resources/polymake/bin/, but you have to set the appropriate library and perl paths first. This basically means executing the export commands you find inside polymake.start prior to calling polymake. The variable $ResourcesDir should point to Resources/
I copied the entire polymake.start script to a new file, then changed just the last line to

Code: Select all

$ResourcesDir/polymake/bin/polymake --script=$1
so now it is just a special purpose "script running" program.

Thanks for all your help!


Return to “Helpdesk”