Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port state resampling to frontend #352

Closed
kai-qu opened this issue Jun 17, 2020 · 4 comments
Closed

port state resampling to frontend #352

kai-qu opened this issue Jun 17, 2020 · 4 comments

Comments

@kai-qu
Copy link
Contributor

kai-qu commented Jun 17, 2020

This first evaluation in the Haskell backend means that the Style functions in the web runtime have to have the same names and types as those in the Haskell backend. It can be removed.

repro bug: on branch baa (or any one that branches off web-runtime), run command runpenrose baa/baa.sub baa/baa.sty baa/baa.dsl, which gives the following error with call stack:

penrose: Cannot find function "pathFromPts"
CallStack (from HasCallStack):
  error, called at src/Penrose/Functions.hs:2697:21 in penrose-0.1.1.1-Fa8716VvZTG6mgRooXV02X:Penrose.Functions
CallStack (from -prof):
  Penrose.Functions.noFunctionError (src/Penrose/Functions.hs:2697:1-66)
  Penrose.Functions.invokeComp.f (src/Penrose/Functions.hs:332:7-61)
  Penrose.Functions.invokeComp.(...) (src/Penrose/Functions.hs:333:7-26)
  Penrose.Functions.invokeComp (src/Penrose/Functions.hs:(326,1)-(334,14))
  Penrose.GenOptProblem.evalExpr.argResult.(...) (src/Penrose/GenOptProblem.hs:842:15-68)
  Penrose.GenOptProblem.evalExpr.argResult (src/Penrose/GenOptProblem.hs:(818,5)-(948,66))
  Penrose.GenOptProblem.evalExpr (src/Penrose/GenOptProblem.hs:(812,1)-(948,66))
  Penrose.GenOptProblem.evalShape.(...) (src/Penrose/GenOptProblem.hs:988:7-74)
  Penrose.GenOptProblem.evalShape (src/Penrose/GenOptProblem.hs:(987,1)-(991,73))
  Penrose.GenOptProblem.evalShapes.(...) (src/Penrose/GenOptProblem.hs:(1003,7)-(1004,68))
  Penrose.GenOptProblem.evalShapes (src/Penrose/GenOptProblem.hs:(1002,1)-(1005,35))
  Penrose.GenOptProblem.genOptProblemAndState.(...) (src/Penrose/GenOptProblem.hs:(1270,7)-(1271,72))
  Penrose.GenOptProblem.genOptProblemAndState (src/Penrose/GenOptProblem.hs:(1249,1)-(1297,6))
  Penrose.GenOptProblem.compileStyle.initState (src/Penrose/GenOptProblem.hs:1322:11-63)
  Penrose.GenOptProblem.compileStyle (src/Penrose/GenOptProblem.hs:(1308,1)-(1331,99))
  Penrose.API.compileTrio (src/Penrose/API.hs:(72,1)-(91,21))
  Penrose.ShadowMain.penroseRenderer (src/Penrose/ShadowMain.hs:(127,1)-(149,45))
  Penrose.ShadowMain.processArgs (src/Penrose/ShadowMain.hs:(68,1)-(85,77))
  Penrose.ShadowMain.shadowMain (src/Penrose/ShadowMain.hs:64:1-68)

Suggested fix from @wodeni:

  • I don’t remember doing any evaluation in compileTrio. The place to change is genOptProblemAndState. Just get rid of the line that calls evalShapes and initialize the list of shapes as an empty list. Do remember to eval the first frame when you get to the frontend
  • I probably missed that because I was only porting old examples, so things actually worked out accidentally
  • Can’t remember if I’m already evaluating shapes when I decode the initial state in the web runtime. Just double check and make sure it does that
@kai-qu
Copy link
Contributor Author

kai-qu commented Jun 17, 2020

@wodeni Can you point me to where the first frame should be evaluated in the frontend, and where the initial state is decoded in the web runtime? I looked at App.tsx but it wasn't immediately clear where to do this.

@wodeni
Copy link
Member

wodeni commented Jun 17, 2020

decodeState is called in Canvas:

public static processData = async (data: any) => {

If you look at Protocol, it's only called upon resample or compilation. I actually evaluate the state immediate after decoding, so I imagine no changes are really needed to get the first frame rendered.

kai-qu pushed a commit that referenced this issue Sep 2, 2020
… but resample still doesn't work for the same reason; fix frontend -> backend JSON (translation conversion); add @keenancrane's hyperbolic `tangentTo` constraint
@kai-qu kai-qu changed the title remove first evaluation of shapes from Haskell backend port shape sampling to frontend Sep 2, 2020
@kai-qu
Copy link
Contributor Author

kai-qu commented Sep 2, 2020

@wodeni Fixed this for now (see commit I just pushed). Thanks for the pointer!

A related issue is that energy-aware resampling in the backend won't work for the same reason—the backend needs to evaluate the energy in order to pick the lowest-energy sample, which then runs into the missing function name issue.

I know you had it on your roadmap to move shape definitions and sampling into the frontend. Can you let me know if you plan to get to it anytime soon (say, in the next two weeks)?

Otherwise, I can do a quick fix in the meantime:

  • frontend requests N resamples
  • backend resamples "naively" (i.e. not evaluating the energy on the state)
  • send the translation with the new values back to the frontend, which handles picking the lowest-energy one

@kai-qu kai-qu changed the title port shape sampling to frontend port state resampling to frontend Sep 2, 2020
@kai-qu
Copy link
Contributor Author

kai-qu commented Mar 24, 2021

Resolved as Haskell is deprecated ✨

@kai-qu kai-qu closed this as completed Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants