OpenQL icon indicating copy to clipboard operation
OpenQL copied to clipboard

OpenQL does not work with pathlib

Open eendebakpt opened this issue 3 years ago • 2 comments

The OpenQL set and set_option methods do not work with pathlib duck typing for str. A minimal example:

import openql as ql
import tempfile
from pathlib import Path

output_dir = Path(tempfile.mkdtemp())
ql.initialize()
ql.set_option('output_dir', output_dir)

results in TypeError: in method 'set_option', argument 2 of type 'std::string const &'

eendebakpt avatar Jan 17 '23 09:01 eendebakpt

Hello Pieter,

Thanks for reporting. It would indeed be nice for that to work.

The Python API of OpenQL is built with SWIG which makes it possible to call the C++ functions from within Python. C++ has obviously no knowledge of pathlib. And it seems that there is no implicit conversion to string done before calling the C++ method.

I would assume that doing the conversion yourself (with str(...)) works just fine?

pablolh avatar Jan 23 '23 10:01 pablolh

Yes, conversion the str works fine. But this is something users will bump into, as pathlib is becoming more the standard, so it would be nice if openql could support this. Perhaps swig has options for this, but I have not checked

eendebakpt avatar Jan 23 '23 18:01 eendebakpt