QuTech-Delft / OpenQL

OpenQL: A Portable Quantum Programming Framework for Quantum Accelerators. https://dl.acm.org/doi/10.1145/3474222
https://openql.readthedocs.io
Other
97 stars 44 forks source link

OpenQL does not work with pathlib #471

Open eendebakpt opened 1 year ago

eendebakpt commented 1 year ago

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 &'

pablolh commented 1 year ago

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?

eendebakpt commented 1 year ago

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