dwavesystems / dwavesystems/dwave-ocean-sdk
File I/O
- Dominant language
- Python
- Stars
- 539
- Forks
- 192
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 2
Description
The data-structures introduced and used by the dwave-ocean-sdk mostly consist of several substructures that might or might not be native to python, e.g. the `class` `dwave.system.EmbeddingComposite` [1] consists of `properties`, such as `EmbeddingComposite.child` and `EmbeddingComposite.parameters`, and `methods`, such as `EmbeddingComposite.sample_qubo(...)`, or the `class` `dimod.SampleSet` [2] consists of `properties`, such as `SampleSet.record`, and `methods`, such as `SampleSet.lowest(...)`.
**However**, it is currently not possible to simply write to files, and read from files in a different script, instaces of them. Please do not consider this a limitation to my examples. I know there are a lot more.
In my opinion a missing feature of the dwave-ocean-sdk is _write-to_ and _read-from_ file(s) all kinds of data-structures related to the dwave packages. For example _NumPy_ offers, apart from many other functions, the functions `writetxt(filename, array)` and `loadtxt(filename)` [3] to easily write arrays to files and also read them in from files.
So far, I also tried to use the python package `pickle` [4] (functions `pickle.dump(obj, file)` for writing and `pickle.load(file)` for reading). On a simple test-case that worked very well for an instance of a `dimod.Sampleset`, but failed for an instance of a `dwave.system.DWaveSampler`, due to some subsub...subsubstructure within, which can not "be pickled".
One could of course also go through all data-structures and recursively all their substructures and decide what data is of interest, but this is of course ... cumbersome ...
I think the pickle package is offering even more than necessary. I think it would be sufficient to I/O data (`properties` in the examples above), while `methods` should be known by the reading script from the corresponding packages. But it should be possible to treat the read data-structures as the ones they were written, e.g. a written instance of a `dwave.system.EmbeddingComposite` should be readable by a different script that imported the packages of the dwave-ocean-sdk, and treat the read data again as an instance of a `dwave.system.EmbeddingComposite`.
Why do I think such a feature is missing:
Currently a lot of research is going on to improve applicability of quantum annealing to real-world problems. But since there are quite some subtleties, there also is a lot of _trial and error_. In this regard, I think it would be beneficial for the community to exchange all kinds of findings **and especially data**. I might even dare to say that the inputs are more interesting than the results, and of course the combination of both would be the most valuable.
1 - [https://docs.ocean.dwavesys.com/en/stable/docs_system/reference/composites.html#embeddingcomposite](https://docs.ocean.dwavesys.com/en/stable/docs_system/reference/composites.html#embeddingcomposite)
2 - [https://docs.ocean.dwavesys.com/en/stable/docs_dimod/reference/sampleset.html#id1](https://docs.ocean.dwavesys.com/en/stable/docs_dimod/reference/sampleset.html#id1)
3 - [https://numpy.org/doc/stable/reference/routines.io.html](https://numpy.org/doc/stable/reference/routines.io.html)
4 - [https://docs.python.org/3/library/pickle.html#](https://docs.python.org/3/library/pickle.html#)
Contributor guide
Assessment
This issue has not been assessed yet.