{ "info": { "author": "QuantumInspire", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "[![Coverage Status](https://coveralls.io/repos/github/QuTech-Delft/qilib/badge.svg?branch=dev)](https://coveralls.io/github/QuTech-Delft/qilib?branch=dev)\n\n# QILib\n\nQuantum Library for the Quantum Inspire platform\n\n## Installation\n\nThe Quantum Inspire Library can be installed from PyPI via pip:\n\n```\n$ pip install qilib\n```\n\n### Installing from source\nClone the qilib repository from https://github.com/QuTech-Delft/qilib and install using pip:\n```\n$ git clone git@github.com:QuTech-Delft/qilib.git\n$ cd qilib\n$ python3 -m venv env\n$ . ./env/bin/activate\n(env) $ pip install .\n```\n\nFor development install in editable mode:\n```\n(env) $ pip install -e .[dev]\n```\n\n### Install Mongo database\nTo use the MongoDataSetIOReader and MongoDataSetIOWriter a mongodb needs to be installed.\nFor Windows, Linux or OS X follow the instructions [here](https://docs.mongodb.com/v3.2/administration/install-community/)\non how to install the database.\n\nAfter installing the database it has to be configured as [replica set](https://docs.mongodb.com/manual/replication/) by\ntyping:\n```\nmongod --replSet \"rs0\"\n```\nand from within the mongo shell initiate with:\n```\nrs.initiate()\n```\n\n## Testing\n\nRun all unittests and collect the code coverage:\n```\n(env) $ coverage run --source=\"./src/qilib\" -m unittest discover -s src/tests -t src\n(env) $ coverage report -m\n```\n\n## Data set\nThe three main building blocks of the qilib data set are a DataArray, DataSet and a DataSetIO that provides a\nstorage backend for the DataSet. \n\n### DataArray\nA DataArray is a wrapper around a numpy array and can be used as one. A data array can also have another, or multiple,\ndata arrays as setpoints. For example, in a 2D-scan, there will be a 1D DataArray for the x-axis variable specifying a discrete set of setpoints\nfor that variable, a 2D DataArray for the y-axis variable using the x-axis DataArray as its values and a 2D DataArray\nfor the measured value.\n\nThe DataArray constructor accepts either:\n+ pre-defined data (numpy arrays)\n+ array shapes (tuple)\n\nThe DataArray makes sure that the dimensions of the set arrays are correct with regards to the data array and vice\nversa. That means, e.g., trying to set a 1D array of 10 elements as the data array with a 1D setpoint array of 8\nelements will raise an error.\n\nAn example of a 2D measurement array, **z**, that is defined by the main setpoint array **x** and secondary setpoint\narray **y**:\n\n```\nimport numpy as np\nfrom qilib.data_set import DataArray\n\nx_size = 10\ny_size = 5\nx_points = np.array(range(x_size))\ny_points = np.tile(np.array(range(y_size)), [x_size, 1])\nx = DataArray(name=\"x\", label=\"x-axis\", unit=\"mV\", is_setpoint=True, preset_data=x_points)\ny = DataArray(name=\"y\", label=\"y-axis\", unit=\"mV\", is_setpoint=True, preset_data=y_points)\nz = DataArray(name=\"z\", label=\"z-axis\", unit=\"ma\", set_arrays=(x,y), shape=(x_size, y_size))\n\n```\n\n### DataSet\nA DataSet object encompasses DataArrays. A DataSet can have multiple measurement arrays sharing the same setpoints.\nIt is an error to have multiple measurement arrays with different setpoints in one DataSet.\n\nA DataSet can be incrementally updated with the `add_data()` method, which takes an index specification, a reference to\nthe array that is to be updated and the update data: `index, {array_name: update_data}}`. In case of multi dimensional\narrays whole rows, or rows of rows, can be updated together. For example:\n```\n# this sets a single element at the 3rd setpoint along the x-axis, 4th along the y-axis\ndataset.add_data((2,3), {'z': 0.23})\n\n# given that dataset is a 10 x 3 2D dataset:\n# this sets the entire y-axis data at the 5th setpoint along the x-axis\n# ie. the data specifies a value for each of the setpoints along the y-axis\ndataset.add_data(4, {'z': [0.23, 2.6, 0.42]})\n```\n\nDataSet specifications:\n+ The constructor may accept DataArrays for setpoints and data arrays. Multiple measurement arrays may be specified as\na sequence.\n+ The DataSet will raise errors on mismatches in array dimensions.\n+ The DataSet will only accept an array if its name does not equal that of any array already in the DataSet.\n+ Arrays can be read by the public property .data_arrays (a dict, key is the DataArray name, value the DataArray).\nIn addition, DataArrays are accessible as properties on the DataSet object (for example, an array with name 'x' added\nto a DataSet data_set can be access as data_set.x).\n+ Updates made to the DataSet will be sent to the underlying DataSetIOWriter if available.\n+ A DataSet can have one, or more, DataSetIOWriters.\n+ A DataSet can be instantiated with one DataSetIOReader but not both a DataSetIOWriter and a DataSetIOReader.\n\n### DataSetIOWriter\nA DataSet can be instantiated with a DataSetIOWriter that provides a storage backend. All changes made on the DataSet\nare pushed to the storage. There are two DataSetIOWriter implementation available, MemoryDataSetIOWriter and\nMongoDataSetIOWriter.\n\n#### MemoryDataSetIOWriter\nProvides an in-memory storage backend that can be used for live plotting of a measurement. All data is kept in memory\nand not stored on disc or in database. MemoryDataSetIOWriter should not be instantiated directly but created, along with\na MemoryDataSetIOReader, using the MemoryDataSetIOFactory. The Reader and Writer share a storage queue used to pass\nupdates from one DataSet to another.\n```\nio_reader, io_writer = MemoryDataSetIOFactory.get_reader_writer_pair()\ndata_set_consumer = DataSet(storage_reader=io_reader)\ndata_set_producer = DataSet(storage_writer=io_writer)\n```\n\n#### MongoDataSetIOWriter\nProvides a connection to a mongo database that needs to be pre-installed. All updates to a DataSet are stored in the\nmongodb database as events that are collapsed, to represent the complete DataSet, when the `finalize()` method is called\non the DataSet. Data can not be written to the database on a finalized DataSet.\n```\ndata_set_name = 'experiment_42'\nwriter = MongoDataSetIOWriter(name=data_set_name)\ndata_set = DataSet(storage_writer=writer, name=data_set_name)\n```\n\n### DataSetIOReader\nClasses that implement the DataSetIOReader interface allow a DataSet to subscribe to data, and data changes, in an\nunderlying storage. To sync from storage the `sync_from_storage(timeout)` method on a DataSet has to be called. There\nare two implementations of the DataSetIOReader, the MemoryDataSetIOReader and MongoDataSetIOReader.\n\n#### MemoryDataSetIOReader\nProvides a way to subscribe to data that is put on a storage queue by a paired MemoryDataSetIOWriter created by the\nMemoryDataSetIOFactory.\n\n#### MongoDataSetIOReader\nThe MongoDataSetIOReader creates a connection to a mongodb and subscribes to changes in the underlying document. To\nupdate a DataSet that has been instantiated with a MongoDataSetIOReader a call on the DataSet's `sync_from_storage(timeout)`\nmethod has to be made. To load a DataSet from the underlying mongodb a static method `load(name, document_id)` can be\ncalled with either the DataSet name or _id or both.\n\nIn the example below, a DataSet is instantiated with MongoDataSetIOReader, synced from storage and the data plotted:\n```\nconsumer_dataset = MongoDataSetIOReader.load(name='experiment_42')\nconsumer_dataset.sync_from_storage(-1)\nplot(consumer_dataset)\n\n```\n\n## Examples\n#### Plot and measure with MemoryDataSetIO\nIn this example a MemoryDataSetIOWriter and MemoryDataSetIOReader pair is created using the MemoryDataSetIOFactory.\nFake measuremet is run on separate thread, feeding fake measurement data to in-memory storage that the consumer data set\nsyncs from with the `sync_from_storage(timeout)` method.\n```python\nimport random\nimport threading\nimport time\n\nimport matplotlib.pyplot as plt\n\nfrom qilib.data_set import DataSet, DataArray\nfrom qilib.data_set.memory_data_set_io_factory import MemoryDataSetIOFactory\n\nx_dim = 100\ny_dim = 100\nstop_measuring = False\n\nio_reader, io_writer = MemoryDataSetIOFactory.get_reader_writer_pair()\ndata_set_consumer = DataSet(storage_reader=io_reader)\nsome_array = DataArray('some_array', 'label', shape=(x_dim, y_dim))\ndata_set_producer = DataSet(storage_writer=io_writer, data_arrays=some_array)\n\nplt.ion()\n\ndef plot_measured_data():\n fig, ax = plt.subplots()\n for i in range(20):\n data_set_consumer.sync_from_storage(-1)\n ax.imshow(data_set_consumer.some_array, cmap='hot', interpolation='nearest')\n fig.canvas.draw()\n return True\n\n\ndef measure_data():\n while not stop_measuring:\n for i in range(x_dim):\n line = [i + j * random.random() for j in range(y_dim)]\n data_set_producer.add_data(i, {'some_array': line})\n time.sleep(0.02)\n\n\nmeasure_thread = threading.Thread(target=measure_data)\nmeasure_thread.start()\nstop_measuring = plot_measured_data()\nmeasure_thread.join()\n```\n#### Plot and measure with MongoDataSetIO\nIn this example one script creates a new DataSet with MongoDataSetIOWriter that stores a copy of the data set in a\nunderlying mongodb which needs to be pre-installed as described above. By instantiating the DataSet with a\nMongoDataSetWriter all updates and additions to the DataSet are reflected in the database. To fetch the data set from\nthe database the static method `load(name, document_id)` provided in MongoDataSetIOReader is used. The method returns a\nnew DataSet object that subscribes to all changes in the underlying data set and can be updated with the\n`sync_from_storage` method.\n\nIn one console run script __A__ and __B__ in another one. Make sure start script __A__ before __B__ as the former\ncreates the data set in the database that the latter attempts to load.\n\n##### A\n```python\nimport random\nfrom time import sleep\n\nimport numpy as np\n\nfrom qilib.data_set import DataSet, DataArray, MongoDataSetIOWriter\n\nx_dim = 100\ny_dim = 100\n\nmeasurements = DataArray(name=\"measurements\", label=\"a-data\", unit=\"ma\",\n preset_data=np.NaN * np.ones((x_dim, y_dim)))\n\n\nwriter = MongoDataSetIOWriter(name='experiment_42')\n\ndata_set = DataSet(storage_writer=writer, name='experiment_42', data_arrays=measurements)\n\nfor i in range(x_dim):\n line = [i + j * random.random() for j in range(y_dim)]\n data_set.add_data(i, {'measurements': line})\n sleep(0.5)\n\ndata_set.finalize()\n```\n\n##### B\n```python\nimport matplotlib.pyplot as plt\n\nfrom qilib.data_set import MongoDataSetIOReader\n\n\nplt.ion()\n\nconsumer_data_set = MongoDataSetIOReader.load(name='experiment_42')\n\nfig, ax = plt.subplots()\n\nwhile not consumer_data_set.is_finalized:\n consumer_data_set.sync_from_storage(0)\n ax.imshow(consumer_data_set.measurements, cmap='hot', interpolation='nearest')\n fig.canvas.draw()\n\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "Other/Proprietary License", "maintainer": "", "maintainer_email": "", "name": "qilib", "package_url": "https://pypi.org/project/qilib/", "platform": "", "project_url": "https://pypi.org/project/qilib/", "project_urls": null, "release_url": "https://pypi.org/project/qilib/0.3.1/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Quantum Library for the Quantum Inspire platform", "version": "0.3.1" }, "last_serial": 5955358, "releases": { "0.2.2": [ { "comment_text": "", "digests": { "md5": "9cb4c52b0afeb1bb06d5e0c11a6f5db7", "sha256": "9d68f6c6e93e23bb1e66f907e674ded2a8ec9624bd575f01bab59e7e67e20190" }, "downloads": -1, "filename": "qilib-0.2.2.tar.gz", "has_sig": false, "md5_digest": "9cb4c52b0afeb1bb06d5e0c11a6f5db7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 29127, "upload_time": "2019-08-08T13:06:03", "url": "https://files.pythonhosted.org/packages/9d/6c/15d9e6af22d5b80b7283d2ea68ec7a837d7c896d0b9829fdbb5d63cc6cbc/qilib-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "19fd3231d71ff7164d6b70171121768a", "sha256": "659d862ff3f06a7b9b46ad71fc9fcb48a55a650ebb8287ea361c74660efcd908" }, "downloads": -1, "filename": "qilib-0.2.3.tar.gz", "has_sig": false, "md5_digest": "19fd3231d71ff7164d6b70171121768a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 35393, "upload_time": "2019-09-16T11:50:35", "url": "https://files.pythonhosted.org/packages/da/36/9624460d0b041b00f7e80429d8658be884a104cec0e709cfdc90f293493f/qilib-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "d4e3a9e53be05a9dad4f52d8a3336789", "sha256": "8290e61c997e266ffbafbc097f4257948f7987213dc15d6dbf113d0d99368f01" }, "downloads": -1, "filename": "qilib-0.2.4.tar.gz", "has_sig": false, "md5_digest": "d4e3a9e53be05a9dad4f52d8a3336789", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 35388, "upload_time": "2019-09-24T11:56:44", "url": "https://files.pythonhosted.org/packages/f7/4b/e4f03f55b33d2aaad66b7dce44188ba897d524e2144b34fa3e825f3ea549/qilib-0.2.4.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "d5022ac0c4177e161afa36a9b9e72829", "sha256": "352f243377cb122fa116b454e41c0b3d85c6fab6ea7cbef341aea9e73a8b9630" }, "downloads": -1, "filename": "qilib-0.3.1.tar.gz", "has_sig": false, "md5_digest": "d5022ac0c4177e161afa36a9b9e72829", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 31937, "upload_time": "2019-10-10T15:02:44", "url": "https://files.pythonhosted.org/packages/30/c9/ba1a3e54c12062ebca46324d803183e49b5b21efb1e4e46f8f7f199a72f3/qilib-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d5022ac0c4177e161afa36a9b9e72829", "sha256": "352f243377cb122fa116b454e41c0b3d85c6fab6ea7cbef341aea9e73a8b9630" }, "downloads": -1, "filename": "qilib-0.3.1.tar.gz", "has_sig": false, "md5_digest": "d5022ac0c4177e161afa36a9b9e72829", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 31937, "upload_time": "2019-10-10T15:02:44", "url": "https://files.pythonhosted.org/packages/30/c9/ba1a3e54c12062ebca46324d803183e49b5b21efb1e4e46f8f7f199a72f3/qilib-0.3.1.tar.gz" } ] }