Export julia code from VSCode to html

Hi everybody !
Some IDEs for instance Pycharm propose export to html format directly from the main menu .
I decided to shift to VSCode (Visual Studio) and expected the same. In vain …
So I began to understand that it was only possible through JuPyter notebook.
I downloaded the JuPyter extension from VSCode and was able to create a new notebook from inside VSC and paste any code inside the cell.
Now i followed instructions to export the resulting i.pynb file.
Drop down menu ‘…’ on the right of tool-bar actually proposes ‘Export’ and asks for format (choice between PDF and HTML ,quite simple and logical). After selection I have a dialog box to select a file name for the output. Well, quite normal again.
After my choice is done NOTHING happens ! NO file is created, NO error message is issued.
I did several attempts with the same (absence of) result.
Did I miss something, did I forget something about parameters.
Thank you for your help.

Did you install python?

No I didn’t

I’ve had a similar problem wrt. exporting a Jupyter notebook as html from VSCode on Windows. I seem to recall that I had to install Python and possibly some package. I never recall what I had to install, though. It is possible that this is simpler on Linux or Mac – I think those have Python installed as part of the OS.

@ BLI
Thank you very much. It works !

Another problem which is reported elsewhere.
Running of very simple Julia scripts through ‘run’ menu of VSCode is very long. Somebody suggested to use command ‘Julia: execute active file in REPL’ result is a little better but nothing to compare with ‘real’ REPL. So it seems to me that I will keep VSCode as a pure editor, debugger but that I will run files ‘from outside’ (REPL or linux notepadqq almost as fast as REPL)

Hm. How “simple” is your code in VSCode?

Be aware of that the first time you run Julia code, there is an overhead in “compiling” the functions you use. If you run the code a second time, it runs much, much faster.

This code for instance:
Purpose is to compare this (searching for perfect numbers <1000000):
function sommeAliquotes(n)
“”“calcule la somme des diviseurs propres de n à l’exclusion de n “””
somme = 1
stop = sqrt(n)
i = 2
while i < stop #condition d’arrêt
if rem(n, i) == 0
somme += i + div(n, i)
end
i += 1
end
if n == i * i # cas des carrés parfaits n/i=i
somme += i
end
return somme
end

parfait(n) = ifelse(sommeAliquotes(n) == n, true, false)#si immédiat

function show()
for n in 2:1000000
if parfait(n)
println(n)
end
end
end

@time show()

with Python equivalent :

import math, time
def sommeAliquotes(n: int) ->int:
somme = 1
i=2
stop = math.sqrt(n)
while i<stop:
if not n%i:
somme=somme+i+n//i
i=i+1
if i*i==n:
somme+=i
return somme

def parfait(n):
return n==sommeAliquotes(n)

debut=time.time()
for n in range(2,1000000):
if parfait(n):
print(n)
fin=time.time()
print(fin-debut)

Actually on this example Julia is always 20 times faster than Python.
But REPL gives immediately
4.428420 seconds (7.16 k allocations: 527.172 KiB, 1.01% compilation time)
and run without debugging gives this result
15.350995 seconds (262.84 k allocations: 18.144 MiB, 0.25% gc time, 6.38% compilation time)
but actually to have this output you must wait more than 20 seconds
Now command: Julia run active file in REPL gives
6.023399 seconds (7.18 k allocations: 523.000 KiB, 0.91% compilation time)
But you must wait the same more than 20 seconds for this output.

This was visible with version 1.6. i do not notice anything with 1.10

Suggestion: Please insert code in a standard Julia computer code environment. In-line code is inserted between back-ticks, while multiline code is inserted between triple backtick followed by “julia”, and ends in triple backtick. This makes it much easier to read the code. Your first function would then be:

function sommeAliquotes(n)
    """calcule la somme des diviseurs propres de n à l’exclusion de n """
    somme = 1
    stop = sqrt(n)
    i = 2
    while i < stop #condition d’arrêt
        if rem(n, i) == 0
            somme += i + div(n, i)
        end
        i += 1
    end
    if n == i * i # cas des carrés parfaits n/i=i
        somme += i
    end
    return somme
end

next,

parfait(n) = ifelse(sommeAliquotes(n) == n, true, false)#si immédiat

and

function show()
    for n in 2:1000000
        if parfait(n)
            println(n)
        end
    end
end

When I run your code in the REPL of my home PC (AMD Ryzen 9 5900HX with Radeon Graphics @ 3.3 GHz, 32 GB RAM):

julia> @time show()
6
28
496
8128
  1.163568 seconds (7.16 k allocations: 527.172 KiB, 1.77% compilation time)

The second time I run it in the REPL, I get:

julia> @time show()
6
28
496
8128
  1.145218 seconds (22 allocations: 928 bytes)

The third and so on time, there are 21 allocations with 624 bytes. OK – in this case, compilation time is not important (it doesn’t take much time), but there is a significant reduction in the allocations.


If I run your code in Jupyter notebook within VSCode, I get the following results… the first time:

julia> @time show()
1.166460 seconds (14.94 k allocations: 1.198 MiB, 1.94% compilation time)

while the subsequent times:

julia> @time show()
1.138408 seconds (53 allocations: 1.406 KiB)

So: I essentially get the same computation time in the REPL and in VSCode/Jupyter notebook, but a bit more allocation in VSCode/Jupyter notebook.

My computer seems to be quite a bit faster than yours. That doesn’t explain the hike in the computation time on your computer when running the code in VSCode/Jupyter notebook. Perhaps your computer has less RAM than mine?

No doubt !
Here are my characteristics
System: Kernel: 5.4.0-186-generic x86_64 bits: 64 compiler: gcc v: 9.4.0
Desktop: Cinnamon 4.6.7 wm: muffin dm: LightDM Distro: Linux Mint 20 Ulyana
base: Ubuntu 20.04 focal
Machine: Type: Laptop System: ASUSTeK product: VivoBook_ASUSLaptop X409BA_M409BA v: 1.0
serial:
Mobo: ASUSTeK model: X409BA v: 1.0 serial: UEFI: American Megatrends
v: X409BA.300 date: 09/10/2019
Battery: ID-1: BAT0 charge: 22.3 Wh condition: 22.3/32.0 Wh (70%) volts: 7.6/7.6
model: ASUSTeK ASUS Battery serial: status: Discharging
CPU: Topology: Dual Core model: AMD A9-9425 RADEON R5 5 COMPUTE CORES 2C+3G bits: 64
type: MCP arch: Excavator L2 cache: 1024 KiB
flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 12376
Speed: 3420 MHz min/max: 1400/3100 MHz Core speeds (MHz): 1: 2883 2: 2778
But my purpose is to motivate teachers to change Python for Julia. Of course for education speed is not the more important but it can be taken into account for some ‘explorations’ in the field of numbers.

You’re completely right. For multi-line comment I did this ‘à la Python’. If it doesn’t cause any error if forces the interpreter to evaluate a string constant. I use both languages and sometimes I’m confused. i will take care in the future
This doesn’t explain my problem delay in execution under VSCode. Difference of performance with your system is quite normal, but your result although better are more consistent. Size of my RAM 8GB maybe the problem is here . IDE are greedy. I will make some additional checking using conky

Things begin to be clear. 8 GB RAM is sufficient although largely used by the process.
But it seems that the problem comes from the CPU. Conky signals CPU1-CPU2 100% used under VSCode. Only 40% with notepadqq or REPL.
This is a hardware problem.
You helped me very much. Thanks again.

In case it’s not clear, BLI’s suggestion regards the text input here on Discourse. The idea is to use Markdown to achieve more readable formatting. This input:

```julia
if rem(n, i) == 0
    somme += i + div(n, i)
end
```

Renders like so:

if rem(n, i) == 0
    somme += i + div(n, i)
end

Wikipedia page on Markdown:

In case it’s not clear, BLI’s suggestion regards the text input here on Discourse. The idea is to use Markdown to achieve more readable formatting. This input:
Thank you nsajko for making things perfectly clear now. Anyway BLI draw my attention on the fact that my multi-line comment was not correct in Julia for this piece of code. Both language Python and Julia, share the same format for online comments only.
I will remember, Have a good day.

1 Like