njpipeorgan / wolfram-language-notebook

Notebook support for Wolfram Language in VS Code
Apache License 2.0
159 stars 11 forks source link

add dynamic by wolfram player #50

Closed asukaminato0721 closed 9 months ago

asukaminato0721 commented 1 year ago

fix https://github.com/njpipeorgan/wolfram-language-notebook/issues/40

This is a prototype, still has some problems. But it works well now.

Player is distributed with Engine, so it's ok to use it.

Some remaining TODOs:

  1. set the wolfram player path in config. (Didn't figure out how to do it). Currently I hard coded it.

  2. if using StartProcess , when close the player window, it will

      Received the following data from kernel (stderr):
      [Mon, 31 Jul 2023 16:06:46 GMT] terminate called after throwing an instance of 'zmq::error_t'
        what():  Interrupted system call

    I don't know how to fix it, so I use Run, but Run will stuck the notebook, so I add & to avoid it. (But I don't know whether it's ok on windows).

    And I don't know use which, RunProcess or Run or StartProcess or may something else? So I use Run since it's available from v1.0, and here stringjoin is safe.

  3. rename the function/varible name if needed.

ref https://gitee.com/asdasd1dsadsa/ZhiHu-asdasd1dsadsa/blob/master/Article/在WolframEngine中用WolframPlayer显示图像和动态内容.md

asukaminato0721 commented 1 year ago

image

njpipeorgan commented 1 year ago

It looks great, thanks for adding this feature.

But I do see some small problems in this implementation:

  1. Wolfram Player is called within handleMainLink. I would suggest putting it in handleOutput, e.g. here.
  2. ToBoxes followed by FreeQ is used to detect when Wolfram Player is needed, but it can cause problems when the expression within the packet should not be evaluated. Instead, you may be able to make use of this boxes variable to do the check.
  3. DynamicBox may interact with variables that are outside the box. Is there a way to detect this? You can then notify the user by rendering an error message.

In terms of the TODOs, here are some potential solutions:

  1. You can add a configuration here for users to set the path to wolframplayer
    • Also add the configuration id to the list here, so that the extension will send its value to the frontend kernel
    • Also add the configuation here
    • Even if the user does not provide the path to wolframplayer, you can probably infer this path using the path to the kernel in $CommandLine.
    • What if the path does not point to a correct wolframplayer? It needs to be checked before calling it.
  2. Another configuration to be added is whether or not enabling this feature, and it can have values e.g. "All Graphics and Dynamics", "Only 3D Graphics and Dynamics", "Disable". You then detect the environment and see if it is possible to enable it (e.g. in a remote development environment, running wolframplayer probably does not make sense). If your decision is contrary to the user's choice, send a notification to the user so that they will not be surprised.
  3. Right now, Run blocks the main link queue or the output queue. You can try wrapping it with LocalSubmit to run asynchronously.
asukaminato0721 commented 1 year ago

Progress

asukaminato0721 commented 1 year ago

- [x] Right now, Run blocks the main link queue or the output queue. You can try wrapping it with LocalSubmit to run asynchronously.

still meet zmq problem.

asukaminato0721 commented 1 year ago
{A,B,C}=ReIm@Table[(Sqrt[2] (a^2 b^2 E^(-3 I t) (-1+4 E^(2/3 I (k \[Pi]+6 t)))+a^4 Cos[3 t]-I b^4 Sin[3 t]))/Sqrt[(a^2+b^2) (a^4+14 a^2 b^2+b^4)+(a^2-b^2)^3 Cos[6 t]],{k,0,2}];
M=(A+B+C)/3;
Manipulate[Block[{a=3,b=2,t=$t},Graphics[{{Circle[{0,0},{a,b}]},{Green,Line[{A,B,C,A}]},{Red,Line@Table[M,{t,0.,$t,2Pi/1000}],Disk[M,0.1]}},PlotRange->1.2Max[a,b]]],{$t,0.,2Pi}]

this code has some problem. Didn't figure out why.

asukaminato0721 commented 1 year ago

I use the $InstallationDirectory

Currently I only set a boolean value.

asukaminato0721 commented 1 year ago

(e.g. in a remote development environment, running wolframplayer probably does not make sense). If your decision is contrary to the user's choice, send a notification to the user so that they will not be surprised.

I tend to let user decide that, it's too complex to enumerate all situations.

asukaminato0721 commented 9 months ago

https://github.com/asukaminato0721/mmaplayer