Pandoc Mermaid filter - html

I am trying to use this pandoc filter to convert markdown to HTML.
This is the example file:
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d
section Critical tasks
Completed task in the critical line :crit, done, 2014-01-06,24h
Implement parser and jison :crit, done, after des1, 2d
Create tests for parser :crit, active, 3d
Future task in critical line :crit, 5d
Create tests for renderer :2d
Add to mermaid :1d
This is the command that I am running:
pandoc file.md -f markdown -o out.html --filter=pandoc-mermaid
This is the error message:
File "D:\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\Anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\Anaconda3\Scripts\pandoc-mermaid.exe\__main__.py", line 7, in <module>
File "D:\Anaconda3\lib\site-packages\pandoc_mermaid_filter.py", line 38, in main
toJSONFilter(mermaid)
File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 130, in toJSONFilter
toJSONFilters([action])
File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 164, in toJSONFilters
sys.stdout.write(applyJSONFilters(actions, source, format))
File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 195, in applyJSONFilters
altered = walk(altered, action, format, meta)
File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 123, in walk
return {k: walk(v, action, format, meta) for k, v in x.items()}
File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 123, in <dictcomp>
return {k: walk(v, action, format, meta) for k, v in x.items()}
File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 110, in walk
res = action(item['t'],
File "D:\Anaconda3\lib\site-packages\pandoc_mermaid_filter.py", line 31, in mermaid
subprocess.check_call([MERMAID_BIN, "-i", src, "-o", dest])
File "D:\Anaconda3\lib\subprocess.py", line 359, in check_call
retcode = call(*popenargs, **kwargs)
File "D:\Anaconda3\lib\subprocess.py", line 340, in call
with Popen(*popenargs, **kwargs) as p:
File "D:\Anaconda3\lib\subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\Anaconda3\lib\subprocess.py", line 1311, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado
Error running filter pandoc-mermaid:
Filter returned error status 1
The folder where the executable is located is apparently added to path. Any ideas on how I could fix it?
Specifications:
Windows 10 Home
pandoc 2.14.0.1
Thanks

Not solving the problem but providing a different way to achieve the same and in case it's useful to others who arrive here:
Mermaid-cli has the feature to act as a preprocessor for Markdown.
As such, you can do the following:
mkdir build
npx -p #mermaid-js/mermaid-cli mmdc -i file.md -o build/output-svg.md
# Generates lots of output-svg-1.svg files linked from the doc
cd build
pandoc output-svg.md -o output.html
It defaults to SVG images (which generally works fine for HTML but fails when targeting PDF). It has a less well documented feature to force PNG generation.
npx -p #mermaid-js/mermaid-cli mmdc -i file.md --outputFormat=png -o build/output-png.md
# Generates lots of output-png-1.png files linked from the doc
cd build
pandoc output-png.md -o output.pdf

I found success with the NPM library which adds a similar Mermaid filter for Pandoc: raghur/mermaid-filter.
You should be able to do:
pandoc file.md -f markdown -o out.html --filter=mermaid-filter
IMPORTANT: On Windows, you need to specify the filter as --filter mermaid-filter.cmd instead of --filter mermaid-filter (I missed this at first and was very confused)

Related

ib_insync "contract can't be hashed"

A process I have that's been running for a couple of years suddenly stopped working.
I avoided updating much in the way of python and packages to avoid that..
I've now updated ib_insync to the latest version, and no improvement. debugging a little gives me this:
the code
import ib_insync as ibis
ib = ibis.IB()
contract = ibis.Contract()
contract.secType = 'STK'
contract.currency = 'USD'
contract.exchange = 'SMART'
contract.localSymbol = 'AAPL'
ib.qualifyContracts(contract)
Result:
File "/Users/macuser/anaconda3/lib/python3.6/site-packages/ib_insync/client.py", line 244, in send
if field in empty:
File "/Users/macuser/anaconda3/lib/python3.6/site-packages/ib_insync/contract.py", line 153, in hash
raise ValueError(f'Contract {self} can't be hashed')
ValueError: Contract Contract(secType='STK', exchange='SMART', currency='USD', localSymbol='AAPL') can't be hashed
Exception ignored in: <bound method IB.del of <IB connected to 127.0.0.1:7497 clientId=6541>>
Traceback (most recent call last):
File "/Users/macuser/anaconda3/lib/python3.6/site-packages/ib_insync/ib.py", line 233, in del
File "/Users/macuser/anaconda3/lib/python3.6/site-packages/ib_insync/ib.py", line 281, in disconnect
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 1306, in info
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 1442, in _log
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 1452, in handle
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 1514, in callHandlers
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 863, in handle
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 1069, in emit
File "/Users/macuser/anaconda3/lib/python3.6/logging/init.py", line 1059, in _open
NameError: name 'open' is not defined
| => python --version
Python 3.6.4 :: Anaconda, Inc.
I am not OP, but have had a similar problem. I am attempting to send an order to IB using ib_insync.
contract = Stock('DKS','SMART','USD')
order = LimitOrder('SELL', 1, 1)
try:
ib.qualifyContracts(contract)
trade = ib.placeOrder(contract, order)
except Exception as e:
print(e)
Here is the exception that is returned:
Contract Stock(symbol='DKS', exchange='SMART', currency='USD') can't be hashed
I understand that lists and other mutable can't be hashed, but I don't understand why this wouldn't work. It pretty clearly follows the examples in the ib_insync docs.
FYI - I was able to resolve this issue by updating to the latest ib_insync version. Perhaps this will help you as well.

Yolo V5 issue "Exception: Dataset not found." on local machine

I am trying to train a model using Yolo V5.
I have the issue of Data base not found.
I have a train, test and valid files that contain all the image and labels files.
I have tested the files on googlecolap and it dose work. However, on my local machine it shows the issue of Exception: Dataset not found.
(Yolo_5) D:\\YOLO_V_5\Yolo_V5\yolov5>python train.py --img 416 --batch 8 --epochs 100 --data /data.yaml --cfg models/yolov5s.yaml --weights '' --name yolov5s_results --cache
Using torch 1.7.0 CUDA:0 (GeForce GTX 1080, 8192MB)
Namespace(adam=False, batch_size=8, bucket='', cache_images=True, cfg='models/yolov5s.yaml', data='.\\data.yaml', device='', epochs=100, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[416, 416], local_rank=-1, log_imgs=16, multi_scale=False, name='yolov5s_results', noautoanchor=False, nosave=False, notest=False, project='runs/train', rect=False, resume=False, save_dir='runs\\train\\yolov5s_results55', single_cls=False, sync_bn=False, total_batch_size=8, weights="''", workers=16, world_size=1)
Start Tensorboard with "tensorboard --logdir runs/train", view at http://localhost:6006/
Hyperparameters {'lr0': 0.01, 'lrf': 0.2, 'momentum': 0.937, 'weight_decay': 0.0005, 'warmup_epochs': 3.0, 'warmup_momentum': 0.8, 'warmup_bias_lr': 0.1, 'box': 0.05, 'cls': 0.5, 'cls_pw': 1.0, 'obj': 1.0, 'obj_pw': 1.0, 'iou_t': 0.2, 'anchor_t': 4.0, 'anchors': 3, 'fl_gamma': 0.0, 'hsv_h': 0.015, 'hsv_s': 0.7, 'hsv_v': 0.4, 'degrees': 0.0, 'translate': 0.1, 'scale': 0.5, 'shear': 0.0, 'perspective': 0.0, 'flipud': 0.0, 'fliplr': 0.5, 'mosaic': 1.0, 'mixup': 0.0}
WARNING: Dataset not found, nonexistent paths: ['D:\\me1eye\\Yolo_V5\\valid\\images']
Traceback (most recent call last):
File "train.py", line 501, in <module>
train(hyp, opt, device, tb_writer, wandb)
File "train.py", line 78, in train
check_dataset(data_dict) # check
File "D:\me1eye\YOLO_V_5\Yolo_V5\yolov5\utils\general.py", line 92, in check_dataset
raise Exception('Dataset not found.')
Exception: Dataset not found.
Internal process exited
(Olive_Yolo_5) D:\me1eye\YOLO_V_5\Yolo_V5\yolov5>
there is a much simpler solution. Just go into data.yaml wherever you saved it and change the relative paths to absolut - i.e. just write the whole path! e.g.
train: C:\hazlab\BCCD\train\images
val: C:\hazlab\BCCD\valid\images
nc: 3
names: ['Platelets', 'RBC', 'WBC']
job done - note, as you are in Windows, there is a known issue in the invocation of tain.py - do not use quotes on the file names in the CLI e.g.
!python train.py --img 416 --batch 16 --epochs 100 --data C:\hazlab\BCCD\data.yaml --cfg ./models/custom_yolov5s.yaml --weights '' --name yolov5s_results --cache
Well! I have also encountered this problem and now I fix it.
All you have to do is to keep train, test, validation (these three folders containing images and labels), and yolov5 folder (that is cloned from GitHub) in the same directory. Also, another thing is that the 'data.yaml' file has to be inside the yolov5 folder.
Command to train the model would be like this:
!python train.py --img 416 --batch 16 --epochs 10 --data ./data.yaml --cfg ./models/yolov5m.yaml --weights '' --name yolov5m_results
The issue is due to not found actual dataset path. I found same issue when i trained the Yolov5 model on custom dataset using google colab, I did the following to resolve this.
Make sure provide correct path of data.yaml of dataset.
Make sure path of dataset in data.yaml should be be corrected.
train, test, and valid key should contain path with respect to the main path of the dataset.
Example data.yaml file given below.
path: /content/drive/MyDrive/car-detection-dataset
train: train/images
val: valid/images
test: test/images
nc: 1
names: ['car']

create Json object in lua

I have attempted to follow the following article and I keep getting module Json module not found.
Convert JSON String to Lua Table?
I am installing Json-lua from luarocks as per the article. Then I am just copying and pasting the code. When I run my lua script I get the following error message.
What am I doing wrong??
root#fusion01:# luarocks install json-lua
Installing https://rocks.moonscript.org/json-lua-0.1-3.rockspec...
Using https://rocks.moonscript.org/json-lua-0.1-3.rockspec... switching to 'build' mode
Cloning into 'json-lua'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (7/7), 16.29 KiB | 0 bytes/s, done.
Checking connectivity... done.
Do not use 'module' as a build type. Use 'builtin' instead.
Updating manifest for /usr/local/lib/luarocks/rocks
json-lua 0.1-3 is now built and installed in /usr/local (license: CC)
root#fusion01:# lua sendjson.lua
lua: sendjson.lua:21: module 'json' not found:
no field package.preload['json']
no file '/usr/local/share/lua/5.2/json.lua'
no file '/usr/local/share/lua/5.2/json/init.lua'
no file '/usr/local/lib/lua/5.2/json.lua'
no file '/usr/local/lib/lua/5.2/json/init.lua'
no file '/usr/share/lua/5.2/json.lua'
no file '/usr/share/lua/5.2/json/init.lua'
no file './json.lua'
no file '/usr/local/lib/lua/5.2/json.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/json.so'
no file '/usr/lib/lua/5.2/json.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './json.so'
stack traceback:
[C]: in function 'require'
sendjson.lua:21: in main chunk
[C]: in ?
root#fusion01:# cat sendjson.lua
#!/bin/lua
--local raw_json_text = JSON:encode(data)
--local pretty_json_text = JSON:encode_pretty(data)
local json = require "json"
local t = {
["name1"] = "value1",
["name2"] = { 1, false, true, 23.54, "a \021 string" },
name3 = json.null
}
local encode = json:encode (t)
print (encode) --> {"name1":"value1","name3":null,"name2":[1,false,true,23.54,"a \u0015 string"]}
local decode = json:decode( encode )
root#fusion01:#

RuntimeError: Lock objects should only be shared between processes through inheritance

I'm getting a ValueError: Lock objects should only be shared between processes through inheritance when writing a xarray.DataArray to_netcdf().
Everything works until writing to disk. But I found a workaround which is to use dask.config.set(scheduler='single-threaded').
Is everyone supposed to use dask.config.set(scheduler='single-threaded') before writing to disk?
Am I missing something?
I tested two schedulers:
1) from dask.distributed import Client; client = Client()
2) import dask.multiprocessing; dask.config.set(scheduler=dask.multiprocessing.get)
python=2.7, xarray=0.10.9, traceback:
File "/home/py_user/miniconda2/envs/v0/lib/python2.7/site-packages/xarray/core/dataarray.py", line 1746, in to_netcdf
return dataset.to_netcdf(*args, **kwargs)
File "/home/py_user/miniconda2/envs/v0/lib/python2.7/site-packages/xarray/core/dataset.py", line 1254, in to_netcdf
compute=compute)
File "/home/py_user/miniconda2/envs/v0/lib/python2.7/site-packages/xarray/backends/api.py", line 724, in to_netcdf
unlimited_dims=unlimited_dims, compute=compute)
File "/home/py_user/miniconda2/envs/v0/lib/python2.7/site-packages/xarray/core/dataset.py", line 1181, in dump_to_store
store.sync(compute=compute)
...
File "/home/py_user/miniconda2/envs/v0/lib/python2.7/multiprocessing/synchronize.py", line 95, in __getstate__
assert_spawning(self)
File "/home/py_user/miniconda2/envs/v0/lib/python2.7/multiprocessing/forking.py", line 52, in assert_spawning
' through inheritance' % type(self).__name__
As #jhamman mentioned in the comments. This may have been fixed in a newer version of Xarray.

octave cannot find fltk XGetUtf8FontAndGlyph symbol

octave 3.8.2 produces this error on loading:
error: /usr/lib64/octave/3.8.2/oct/x86_64-pc-linux-gnu/PKG_ADD: /usr/lib64/octave/3.8.2/oct/x86_64-pc-linux-gnu/__init_fltk__.oct: failed to load: /usr/lib64/fltk/libfltk_gl.so.1.3: undefined symbol: XGetUtf8FontAndGlyph
error: called from:
error: /usr/lib64/octave/3.8.2/oct/x86_64-pc-linux-gnu/PKG_ADD at line 6, column 1
GNU Octave, version 3.8.2
I obtain the following information about configuration of graphics libraries
octave:1> octave_config_info().GRAPHICS_LIBS
ans = -L/usr/lib64/fltk -Wl,-rpath,/usr/lib64/fltk -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -lfltk_gl -lGLU -lGL -lfltk -lXcursor -lXfixes -lXext -ldl -lm -lX11
and although no graphic toolkits are evidently loaded initially,
octave:2> available_graphics_toolkits
ans = {}(1x0)
I can register them subsequently,
octave:3> register_graphics_toolkit("gnuplot")
octave:4> available_graphics_toolkits
ans =
{
[1,1] = gnuplot
}
octave:5> register_graphics_toolkit("fltk")
octave:6> available_graphics_toolkits
ans =
{
[1,1] = fltk
[1,2] = gnuplot
}
but attempting to load fltk produces an error consistent with the initial warning
octave:7> graphics_toolkit("fltk")
error: feval: /usr/lib64/octave/3.8.2/oct/x86_64-pc-linux-gnu/__init_fltk__.oct: failed to load: /usr/lib64/fltk/libfltk_gl.so.1.3: undefined symbol: XGetUtf8FontAndGlyph
error: called from:
error: /usr/share/octave/3.8.2/m/plot/util/graphics_toolkit.m at line 74, column 5
and of course attempting to plot anything also fails,
octave:8> plot(1:10)
error: feval: /usr/lib64/octave/3.8.2/oct/x86_64-pc-linux-gnu/__init_fltk__.oct: failed to load: /usr/lib64/fltk/libfltk_gl.so.1.3: undefined symbol: XGetUtf8FontAndGlyph
error: called from:
error: /usr/share/octave/3.8.2/m/plot/util/graphics_toolkit.m at line 74, column 5
error: failed to load fltk graphics toolkit
error: base_graphics_toolkit::initialize: invalid graphics toolkit
error: /usr/share/octave/3.8.2/m/plot/util/figure.m at line 94, column 9
error: /usr/share/octave/3.8.2/m/plot/util/gcf.m at line 63, column 9
error: /usr/share/octave/3.8.2/m/plot/util/newplot.m at line 113, column 8
error: /usr/share/octave/3.8.2/m/plot/draw/plot.m at line 219, column 9
Both octave and fltk were compiled from source under gentoo:
x11-libs/fltk-1.3.3-r2:1 USE="opengl -cairo -debug -doc -examples -games -pdf -static-libs -threads -xft -xinerama"
sci-mathematics/octave-3.8.2:0/3.8.2 USE="X doc glpk gnuplot gui imagemagick opengl qhull qrupdate readline sparse zlib -curl -fftw -hdf5 -java -jit -postscript -static-libs"
resulting in configure switches of (for the fltk library):
./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --includedir=/usr/include/fltk --libdir=/usr/lib64/fltk --docdir=/usr/share/doc/fltk-1.3.3-r2/html --enable-largefile --enable-shared --enable-xdbe --disable-localjpeg --disable-localpng --disable-localzlib --disable-debug --disable-cairo --enable-gl --disable-threads --disable-xft --disable-xinerama
and (for octave)
./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --libdir=/usr/lib64 --disable-silent-rules --disable-dependency-tracking --docdir=/usr/share/doc/octave-3.8.2 --enable-shared --disable-static --localstatedir=/var/state/octave --with-blas=-L/usr/lib64/blas/reference -lblas --with-lapack=-llapack -L/usr/lib64/blas/reference -lblas --enable-docs --disable-java --enable-gui --disable-jit --enable-readline --without-curl --without-fftw3 --without-fftw3f --disable-fftw-threads --with-glpk --without-hdf5 --with-opengl --with-qhull --with-qrupdate --with-arpack --with-umfpack --with-colamd --with-ccolamd --with-cholmod --with-cxsparse --with-x --with-z --with-magick=GraphicsMagick
If I examine libfltk_gl.so.1.3 with nm, I see that the following symbols are exported:
$ nm -D /usr/lib64/fltk/libfltk_gl.so.1.3
U XCreateColormap
U XGetUtf8FontAndGlyph
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
U _Z10fl_measurePKcRiS1_i
000000000000e170 T _Z10gl_descentv
000000000000e590 T _Z10gl_measurePKcRiS1_
... <snip>
According to nm manual, the U designates that the symbol is global (external) but unknown. My question is whether this unknown symbol status is the origin of the error reported from octave, suggesting that the problem lies with how fltk was compiled, or whether the octave compilation is somehow at fault.
Edit: Solved by enabling Xft support: Please see comments below, and I thank Andy again for his help.
XGetUtf8FontAndGlyph should be in libfltk.so.1.3.
nm -D /usr/lib/x86_64-linux-gnu/libfltk.so.1.3 |grep XGetU
00000000000c2fc0 T XGetUtf8FontAndGlyph
It's very likely that this is a problem with your configure flags for fltk and not GNU Octave. Just try it with the default settings first.
You can test if the UTF8 stuff with OpenGL is okay with the "cube" test. Just digg into the fltk-source dir tests:
cd fltk-1.3.3/test
make cube && ./cube
Does the text in the lower left of the GL window show up?
Had a similar problem. Was getting the following error while trying to run octave (undefined symbol: _ZN18Fl_XFont_On_Demand5valueEv):
bash-4.3$ octave
error: /usr/local/lib/octave/4.0.2/oct/i686-pc-linux-gnu/PKG_ADD: /usr/local/lib/octave/4.0.2/oct/i686-pc-linux-gnu/__init_fltk__.oct: failed to load: /usr/lib/libfltk_gl.so.1.3: undefined symbol: _ZN18Fl_XFont_On_Demand5valueEv
error: called from
/usr/local/lib/octave/4.0.2/oct/i686-pc-linux-gnu/PKG_ADD at line 3 column 1
Command nm -D /usr/lib/libfltk_gl.so.1.3 showed that symbol _ZN18Fl_XFont_On_Demand5valueEv is undefined (with U):
0000a3d4 T _ZN14Fl_Glut_WindowD1Ev
0000a3d4 T _ZN14Fl_Glut_WindowD2Ev
U _ZN18Fl_Font_DescriptorD1Ev
U _ZN18Fl_Graphics_Driver11clip_regionEP8_XRegion
U _ZN18Fl_XFont_On_Demand5valueEv
The solution was to apply a patch file mentioned here to some files inside source directory of FLTK-1.3.3 and then recompile and reinstall FLTK. Now octave works with FLTK without any problem.