quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.85k stars 313 forks source link

Quarto in VS Code tries to run the MatLab Jupyter kernel rather than the built in MatLab plug-in in VS-Code #9067

Closed ncworstell closed 7 months ago

ncworstell commented 7 months ago

Bug description

When I generate the Markdown preview of a quarto document with MatLab code in it, it tries to run the MatLab kernel for jupyter and does not give the option or seem to look for the MatLab plug-in for VS Code. Presumably this is because the MatLab plug-in only recently started to support code execution (https://marketplace.visualstudio.com/items?itemName=MathWorks.language-matlab)

Steps to reproduce

---
title: "Untitled"
format: html
---

```{matlab}
ver

### Expected behavior

Something like this should output (I have XXX'd out personal information) should appear in the pdf output.
````bash
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 23.2.0.2365128 (R2023b)
MATLAB License Number: XXXXXXXXX
Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 19045)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB                                                Version 23.2        (R2023b)
Simulink                                              Version 23.2        (R2023b)
Bioinformatics Toolbox                                Version 23.2        (R2023b)
Computer Vision Toolbox                               Version 23.2        (R2023b)
Curve Fitting Toolbox                                 Version 23.2        (R2023b)
DSP System Toolbox                                    Version 23.2        (R2023b)
Deep Learning Toolbox                                 Version 23.2        (R2023b)
Fuzzy Logic Toolbox                                   Version 23.2        (R2023b)
Global Optimization Toolbox                           Version 23.2        (R2023b)
Image Processing Toolbox                              Version 23.2        (R2023b)
MATLAB Compiler                                       Version 23.2        (R2023b)
MATLAB Compiler SDK                                   Version 23.2        (R2023b)
Optimization Toolbox                                  Version 23.2        (R2023b)
PLS_Toolbox                                           Version 9.3         (24529) 
Parallel Computing Toolbox                            Version 23.2        (R2023b)
Signal Processing Toolbox                             Version 23.2        (R2023b)
SimBiology                                            Version 23.2        (R2023b)
Spreadsheet Link                                      Version 23.2        (R2023b)
Statistics and Machine Learning Toolbox               Version 23.2        (R2023b)
Symbolic Math Toolbox                                 Version 23.2        (R2023b)
Wavelet Toolbox                                       Version 23.2        (R2023b)

Actual behavior

image

Your environment

-IDE: VSCode Version: 1.87.1 (user setup) Commit: 1e790d77f81672c49be070e04474901747115651 Date: 2024-03-06T00:21:36.258Z Electron: 27.3.2 ElectronBuildId: 26836302 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Windows_NT x64 10.0.19045

Quarto check output

A new release of Deno is available: 1.28.2 → 1.41.2 Run `deno upgrade` to install it.

[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.3.450
      Path: C:\Users\worstn\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.11.4
      Path: C:/Users/worstn/AppData/Local/Programs/Python/Python311/python.exe
      Jupyter: 5.3.1
      Kernels: python3, jupyter_matlab_kernel

(\) Checking Jupyter engine render....0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[>] Checking Jupyter engine render....OK

[>] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/
mcanouil commented 7 months ago

VSCode Quarto extension repository is https://github.com/quarto-dev/quarto.

Note that Quarto is a CLI. So even if the VSCode extension can use the the other extension, a kernel is still needed to render the document the same way a Jupyter Notebook will need the kernel. Are you saying that you don't need to specify the MatLab kernel inside Jupyter Notebook when using the MatLab extension?

Could you properly format your post using code blocks for code and terminal outputs? Thanks. If your code contains code blocks, you need to enclose it using more backticks, i.e., usually four ````. Currently it's not very legible.

cderv commented 7 months ago

@ncworstell can you format your issue correctly please ? This way will be able to look at your example correctly.

See https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us

thanks !

ncworstell commented 7 months ago

@cderv, I think I updated it properly. Please let me know how else I can help/what else I might need to correct.

mcanouil commented 7 months ago

@ncworstell GitHub uses markdown. You only have to edit your post to make it "pretty". Take a look at the current formatting, you have quarto check output outside of a code block, you have a weird sections headers in the middle, etc. In particular, take a look at your "Expected behavior" section and how it is formatted.

You can use the "preview" button to see your formatting. image

cderv commented 7 months ago

Thanks for the example @ncworstell

As context and reminder, Quarto will use Jupyter and its kernel to run the code cell you provide. More on this at https://quarto.org/docs/computations/python.html

VS Code or not, this is how Quarto runs - VS Code extension of Quarto (Render or Preview button) will only call quarto render which will have Jupyter processing in the rendering.

That being said, Jupyter kernel detection is explained at https://quarto.org/docs/computations/python.html#kernel-selection In your case this applies

If no Jupyter kernel is specified, then the kernel is determined by finding an available kernel that supports the language of the first executable code block found within the file (e.g. ```{python}).

When using matlab as a code cell language, quarto will try to find an installed Jupyter kernel that supports matlab. As no error on finding it is reported, I believe it found one, and you may have Matlab kernel installed.

I don't know which one, but I know one of them is not supporting correctly some jupyter technical things that prevent its usage in quarto

The error you have is the one reported there. Discussion in quarto about this is at

The issue at https://github.com/mathworks/jupyter-matlab-proxy/issues/48 lead to some other project https://github.com/allefeld/mkernel

I hope this clarifies how quarto works.

You can understand now that quarto render won't be able to leverage the Matlab plug-in. Any rendering happens through Jupyter engine or knitr engine for now. So matlab needs to be used though Jupyter. It won't be able to use a VS Code plugin - especially because outside of VSCode this would obviously not work, and quarto is a CLI tool.

Hope this helps.

I'll close this as the kernel issue you have is reported upstream already; Please to reopen if you think I missed your point; Thanks !