Load file from command line, elaborate, print output

Questions and problems about using polymake go here.
V123E
Posts: 1
Joined: 28 Oct 2020, 10:29

Load file from command line, elaborate, print output

Postby V123E » 28 Oct 2020, 10:46

Hi all! I am facing some troubles in doing a simple thing with polymake: What I would like to do is, from the command line, load a polytope in polymake, expressed through H-Description - equalities and inequalities -, print vertices, and have them saved on a file.
I have done a web search and I found that something like that should work:

Code: Select all

polymake 'my $p=load("MyPol.poly"); print $p->VERTICES;' > MyOut.txt
However, it sounds like my file "MyPol.poly" is not properly wrote, as I face the error

Code: Select all

line 2: ill-formed section header
I have tried three different formats for the .poly file:

Code: Select all

new Polytope(INEQUALITIES=>[...], EQUATIONS=>[...])

Code: Select all

Polytope(INEQUALITIES=>[...], EQUATIONS=>[...])

Code: Select all

(INEQUALITIES=>[...], EQUATIONS=>[...])
But the three of them return the same error and I am not able to figure out a suitable format. I should generate it automatically because it contains hundreds of inequalities and equalities.

Thank you for helping.

lkastner
Developer
Posts: 12
Joined: 27 May 2012, 23:35

Re: Load file from command line, elaborate, print output

Postby lkastner » 29 Oct 2020, 17:07

When using load the data needs to be in json(or previously xml) format. You can have a look at this as follows in polymake:

Code: Select all

$p = cube(2); $p->name="square"; save($p);
Then open the file square.poly to see what it looks like.

Maybe if you do the following you can fix your issue. Change the content of MyPol.poly to

Code: Select all

use application "polytope"; my $p = new Polytope(INEQUALITIES=>[...], EQUATIONS=>[...]); print $p->VERTICES; save_data($p->VERTICES, "vertices.txt");
and then run it with polymake --script MyPol.poly. Then there should be a file vertices.txt containing the vertices (as json/xml). Furthermore it should print the vertices to the screen.

paulcheung
Posts: 14
Joined: 06 Oct 2020, 03:45

Re: Load file from command line, elaborate, print output

Postby paulcheung » 28 Apr 2022, 14:43

Can I ask a follow-up simple question?

When you save the files (say .txt or .poly), where can we find it from file directory? Thanks!

User avatar
gawrilow
Main Author
Posts: 425
Joined: 25 Dec 2010, 17:40

Re: Load file from command line, elaborate, print output

Postby gawrilow » 28 Apr 2022, 14:52

When you are specifying your files by a relative path (not starting with /), they will land in your current working directory. There is nothing special about it in polymake. You can manipulate and query the current working directory from within polymake session or scripts using standard perl commands chdir and Cwd::getcwd.

If you are writing files using open and print statements, be sure to check for errors. If you specify a wrong path (a non-existing directory or one where yuo don't have write permissions), the open and print commands will fail silently; you'll think that everything works but in fact nothing will be written to the disk. Always use the following pattern:

Code: Select all

open MY_FILE, ">path/to/my_file.txt" or die "can't create my file: $!\n"; print MY_FILE my_data(); close MY_FILE;
The magic variable $! included in the error message will contain a brief description of the problem.

paulcheung
Posts: 14
Joined: 06 Oct 2020, 03:45

Re: Load file from command line, elaborate, print output

Postby paulcheung » 28 Apr 2022, 15:10

Thank you so much for the prompt reply!!!

I am very new to this terminal/command language. I would like to ask a very stupid question.

After I typed,

save_data($p->FACETS, "mypoly.txt");

Where can I see this txt file? I have no idea what my current working directory is..... Thank you!!!

paulcheung
Posts: 14
Joined: 06 Oct 2020, 03:45

Re: Load file from command line, elaborate, print output

Postby paulcheung » 28 Apr 2022, 15:31

I tried to follow your instructions, but nothing came up..

My screenshot is attached. Thank you in advance!!
Attachments
Screenshot 2022-04-28 093004.png
(19.12 KiB) Not downloaded yet

User avatar
gawrilow
Main Author
Posts: 425
Joined: 25 Dec 2010, 17:40

Re: Load file from command line, elaborate, print output

Postby gawrilow » 28 Apr 2022, 16:35

Where can I see this txt file? I have no idea what my current working directory is.
Your current working directory is where you started your polymake session, until you changed it explicitly using a "chdir" command. You must have entered the "polymake" command in a Linux shell. The current working directory is usually displayed in the "prompt" string, to the left from the input area. If it's your home directory, it will be abbreviated as "~".

User avatar
gawrilow
Main Author
Posts: 425
Joined: 25 Dec 2010, 17:40

Re: Load file from command line, elaborate, print output

Postby gawrilow » 28 Apr 2022, 16:38

I tried to follow your instructions, but nothing came up..
"chdir" should take an argument, a string with a path to a directory where you want to change into. Without arguments, it uses the variable $_, which most probably contained some garbage value, not pointing to any existing directory. Then it fails silently and the current directory is not changed.

"Cwd::getcwd" returns a string, you should print it to see the result: print Cwd::getcwd;

paulcheung
Posts: 14
Joined: 06 Oct 2020, 03:45

!!

Postby paulcheung » 28 Apr 2022, 17:24

Where can I see this txt file? I have no idea what my current working directory is.
Your current working directory is where you started your polymake session, until you changed it explicitly using a "chdir" command. You must have entered the "polymake" command in a Linux shell. The current working directory is usually displayed in the "prompt" string, to the left from the input area. If it's your home directory, it will be abbreviated as "~".
Thank you for your patience... I know these are super elementary but I am really stressed out about it... Your help is greatly appreciated!!! (since I really couldn't google any useful information for newbie like me)

A little bit background. I am using window subsystem for Linux and installed Ubuntu into it.

I printed a polymake using $p->FACETS. However, I had a big trouble: the output windows do not have enough lines to show it (The default height is 9000. I already tried to set in to 90000, but it shows at most 32767. I later found that it is the biggest height that it can be)

Therefore, I am trying to save the print to a txt file. Then, I should be able to read it by "opening" the txt file. I follow the instruction above (thank you so much) by typing

save_data($p->FACETS, "mypoly.txt");

It seems to be working. However, I really couldn't locate the file from file explorer. When I type pwd (I just found this basic command from the internet), I get

/home/<my user name>

where <my user name> is my user name. I didn't display it since it is unnecessary info. I don't know where it is actually. It does not look like the usual file directory we use in Window. I know Linux uses frontslash, but I have no idea where it IS.

It is just very frustrating that why such elementary information is nowhere to be found on the internet. Every help/troubleshoot seems to assume I need to know something beforehand, but the fact is I know nothing. Thank you so much in advance!!!!!!!
Last edited by paulcheung on 28 Apr 2022, 17:31, edited 1 time in total.

User avatar
gawrilow
Main Author
Posts: 425
Joined: 25 Dec 2010, 17:40

Re: Load file from command line, elaborate, print output

Postby gawrilow » 28 Apr 2022, 17:30


save_data($p->FACETS, "mypoly.txt");
Also keep in mind that you can specify absolute paths in save() and save_data() commands. You can just type "/ and then use tab completion to navigate through your local disk. Or type "~/ to start within your home directory.


Return to “Helpdesk”