NEU-Coop-2024 / helical-jupyter

0 stars 0 forks source link

Process DOT code and output the compiled graph #2

Open etosch opened 1 month ago

etosch commented 1 month ago

The echo append cell magics collected cell text, executed it, and printed "Success!" at the end. You are going to modify that code in a critical way: instead of calling exec on Python code, you are going to call the DOT language executable on DOT language code. The result of that execution should be an image, which you are going to render in the canvas that follows the code cell.

You may face some challenges when addressing this task:

  1. You will need to call an external executable. It is possible that there are Python packages that will interpret DOT code for you -- if you find them, post them in a comment here and we can discuss whether it makes sense to use them.
  2. If, when calling the DOT executable, the code does not compile, you may not know (it depends on how error reporting is handled between the executable, Python, and Jupyter). Before running any code, have two test cases on hand: an example DOT file that you have written and compiled externally and an example DOT file that does not compile. When you end-to-end test your system, copy each of these program into a new notebook (do not put them in the same notebook) to verify the workflow.
  3. If you use the executable, it will probably write the output to disk. This will require naming a file. For now use f'graph_{datetime()}' (or some variation on the timestamp). If there exists a library that processes DOT files, you will likely get the image back in memory as a matrix (e.g., a numpy array type) or an Image object.
kyang04 commented 1 month ago

I think the python package for Graphviz allows you to render DOT code into an image file, which you can then display using an IPython method

https://pypi.org/project/graphviz/