aldenwalker / shine

surface visualizer
2 stars 0 forks source link

Errors in `ipython shine.py` with python 3 #1

Open jibnew opened 1 year ago

jibnew commented 1 year ago

ipython shine.py gives me this error:

  File ~/.local/shine-master/shine.py:926
    print "We have more than 1 visible subsegment?"
    ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

(ipython version 8.16.1)

aldenwalker commented 1 year ago

This is because I wrote shine back in olden times, and I guess I was using python 2. It seems like it would be reasonable to run it through a 2 to 3 converter or something like that.

jibnew commented 1 year ago

Thank you for the explanation! I did it with 2to3, now it runs but this time it produces another error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.11/tkinter/__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/home/me/.local/shine/shine.py", line 519, in open_file
    self.reset()
  File "/home/me/.local/shine/shine.py", line 554, in reset
    self.emsurf_displayer.reset()
  File "/home/me/.local/shine/shine.py", line 874, in reset
    self.canvas_redraw()
  File "/home/me/.local/shine/shine.py", line 1020, in canvas_redraw
    self.recompute_drawing()
  File "/home/me/.local/shine/shine.py", line 905, in recompute_drawing
    T_visible_only = self.draw_viewer.sort_triangles(T_visible_only)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/me/.local/shine/R3.py", line 170, in sort_triangles
    sorted_T = sorted(T, key=lambda x: ((x[0]+x[1]+x[2])/3.0 -self.eye).norm(), reverse=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/me/.local/shine/R3.py", line 170, in <lambda>
    sorted_T = sorted(T, key=lambda x: ((x[0]+x[1]+x[2])/3.0 -self.eye).norm(), reverse=True)
                                        ~~~~~~~~~~~~~~~^^~~~
TypeError: unsupported operand type(s) for /: 'Vector' and 'float'
aldenwalker commented 1 year ago

Hmm that is a little more confusing. Honestly there’s got to be a better program out there for what shine was supposed to do. Actually there’s a javascript version on my website aldenwalker.org that might be easier to get working. What were you looking to do?

jibnew commented 1 year ago

Hmm that is a little more confusing. Honestly there’s got to be a better program out there for what shine was supposed to do. Actually there’s a javascript version on my website aldenwalker.org that might be easier to get working. What were you looking to do?

I have very specific task. For a a group F, a simplicial set X, a natural number n and two permutations, s of {0,...,n} and t of {0,...,n+1}, I compose two maps, F^{Xn} → F^{X{n+1}} → F^{X{n+2}}, where the first sends a function f to the product of (fd{s(i)})^{(-1)^{s(i)}}, i=0,...,n, and the second to (fd_{t(i)})^{(-1)^{t(i)}}, i=0,...,n+1. When F is abelian, this composite is zero since it is d^2 in a cochain complex. Thus in general value of this composite on any f is a product of commutators. Ultimate goal is to find s and t for which this commutator length is smallest. With n up to 7 I managed to do it "by hand" but there are several candidates, and I could not guess the general pattern. With scallop I am computing these commutator lengths for X generic, F free on X and f inclusion of generators; with wallop I am trying to look at a projection of the actual surface, and with shine I was hoping to somehow see it in 3d...

aldenwalker commented 12 months ago

This is an interesting problem! Yeah one problem, or perhaps just interesting thing, is when there is more than one extremal surface (in which case there's infinitely many), you'll get one of them, but maybe it's hard to see a pattern because you're just getting a single one. I can't remember whether there is a way to get a description of the extremal polyhedron. Wallop is definitely great for playing with fatgraphs, and it would be nice to make a javascript version that doesn't need to get built and depend on old graphics libraries. I've never really been able to make much of the actual surfaces (i.e. pulling the fatgraphs to make them into what we normally think of as surfaces in 3d). Somehow the fatgraph has always ended up being the right place, since it remembers the combinatorics.

Oh and I see you said "commutator length" and my brain inserted "stable" in front. Have you been able to successfully find commutator lengths? Those ILP problems become intractable so quickly, which I guess maybe is why you wanted to use Gurobi!

jibnew commented 11 months ago

This is an interesting problem! Yeah one problem, or perhaps just interesting thing, is when there is more than one extremal surface (in which case there's infinitely many), you'll get one of them, but maybe it's hard to see a pattern because you're just getting a single one. I can't remember whether there is a way to get a description of the extremal polyhedron. Wallop is definitely great for playing with fatgraphs, and it would be nice to make a javascript version that doesn't need to get built and depend on old graphics libraries. I've never really been able to make much of the actual surfaces (i.e. pulling the fatgraphs to make them into what we normally think of as surfaces in 3d). Somehow the fatgraph has always ended up being the right place, since it remembers the combinatorics.

Oh and I see you said "commutator length" and my brain inserted "stable" in front. Have you been able to successfully find commutator lengths? Those ILP problems become intractable so quickly, which I guess maybe is why you wanted to use Gurobi!

Sorry for not answering for a while, I sincerely appreciate your interest! Yes, I specifically need cl, not scl. My main obstacle currently is not with speed, I managed to compute cl without Gurobi relatively quickly, but the problem is that the number of variables grows quadratically: the last case I did was n=7 with 21 variables while the next one is 28 and I ran out of alphabet letters. Do you think it is possible to make scallop work with more than 26 variables? As for the results, it seems that cl also grows quadratically. The minimum is attained (among others) on the permutations s=identity and t=reverse; for n there are n(n-1)/2 variables and cl seems to be (n-2)(n-3)/2 but it is too early to speak about any conjectural pattern. I am really curious about the actual commutator expression and the resulting surface.

aldenwalker commented 11 months ago

Sorry I missed this -- it's definitely possible to make scallop work with more than 26 gens. The main problem is deciding what the input looks like. For -cyclic, we need to specify the group -- maybe that's just a list of orders of the factors, or 0 for Z, like 0,3,0,0,0 or something. Then each word in the chain could be a (comma-separated?) list of signed numbers of generator indices? like 0,1,-0,-0,-1,-1 0,1 for abAABB+ab?

jibnew commented 11 months ago

Sorry I missed this -- it's definitely possible to make scallop work with more than 26 gens. The main problem is deciding what the input looks like. For -cyclic, we need to specify the group -- maybe that's just a list of orders of the factors, or 0 for Z, like 0,3,0,0,0 or something. Then each word in the chain could be a (comma-separated?) list of signed numbers of generator indices? like 0,1,-0,-0,-1,-1 0,1 for abAABB+ab?

Well it is certainly up to you to decide - the way it would be easier for you to code. If you then describe the input rules, I (and any other user) would gratefully learn them for sure.

aldenwalker commented 11 months ago

ok cool -- just to check, are you using the -cyclic mode? (I would expect this to be best for groups with larger rank)

jibnew commented 11 months ago

ok cool -- just to check, are you using the -cyclic mode? (I would expect this to be best for groups with larger rank)

Yes, I do not need anything else

aldenwalker commented 11 months ago

Alright I managed to compile scallop, and I had a look at the code. I think it shouldn't be technically difficult, although I don't remember how things work, so it may take me a while to do it in such a way that it doesn't break anything.... Anyway, I will plug away at this at let you know when I have something to try

aldenwalker commented 11 months ago

Ok I just pushed an update -- see if it works for you. Check the -cyclic examples for how to enter the word -- it's basically what I said above.

jibnew commented 11 months ago

Ok I just pushed an update -- see if it works for you. Check the -cyclic examples for how to enter the word -- it's basically what I said above.

Great news! Hope to do it today.

jibnew commented 11 months ago

It works! And the speed is decent, the pattern 1,3,3,6,6,10,10,15,15,21,21,... continues (currently at the 30th term).

One aside question. By some reason for

scallop -c -C abcdefghijkAFlmnoGKpqrLBDNsQtIHTPuOECMURSJ

integer GLPK preprocessing takes much much much more time than for most words of the same length. Can you see what is so special about this particular word compared to others?

aldenwalker commented 11 months ago

Sadly once things get turned over the LP solver who knows what is happening. Because integer linear programming is NP-complete, whether it solves and how long it takes depends wildly on the particular solver and solver options. If you want to push the limits, it's probably worth it to try to get gurobi to work. I would guess that it would be easier to get the "output to file and solve with gurobi" path to work rather than the "build and link with gurobi", although this would add steps to the solve process. Is this something you would be interested in?