From 7f67ce2464b001cecb46fe08f398a96df548d21b Mon Sep 17 00:00:00 2001 From: michaelcroquette <45485610+michaelcroquette@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:00:25 +0200 Subject: [PATCH] Removed the use of quamash which is outdated. Single works fine but is delayed in IPython (jupyter) --- pyrpl/async_utils.py | 40 +++++------ pyrpl/hardware_modules/scope.py | 8 +-- .../test_ipython_notebook/test_notebook.ipynb | 72 +++++++++++++++---- 3 files changed, 78 insertions(+), 42 deletions(-) diff --git a/pyrpl/async_utils.py b/pyrpl/async_utils.py index a3d706ba9..72ad75f32 100644 --- a/pyrpl/async_utils.py +++ b/pyrpl/async_utils.py @@ -3,7 +3,7 @@ It provides the 3 functions: * ensure_future(coroutine): schedules the task described by the coroutine and returns a Future that can be used as argument of - the follo='3.7': # this way, it was not possible to execute wait - # behind a qt slot !!! - # LOOP.run_until_complete(new_future) - # done, pending = new_future.result() - #else: - loop = QtCore.QEventLoop() - def quit(*args): - loop.quit() - new_future.add_done_callback(quit) - loop.exec_() - done, pending = new_future.result() - if future in done: - return future.result() - else: - raise TimeoutError("Timout exceeded") + #assert isinstance(future, Future) or iscoroutine(future) + new_future = wait_for(future, timeout) + LOOP = get_event_loop() + try: + return LOOP.run_until_complete(new_future) + except TimeoutError: + print(("Timout exceeded")) + def sleep(time_s): """ diff --git a/pyrpl/hardware_modules/scope.py b/pyrpl/hardware_modules/scope.py index 07ae8c766..03cb05d44 100644 --- a/pyrpl/hardware_modules/scope.py +++ b/pyrpl/hardware_modules/scope.py @@ -495,7 +495,7 @@ def _data_ch1(self): return np.array( np.roll(self._rawdata_ch1, - (self._write_pointer_trigger + self._trigger_delay_register + 1)), - dtype=np.float) / 2 ** 13 + dtype=float) / 2 ** 13 @property def _data_ch2(self): @@ -503,21 +503,21 @@ def _data_ch2(self): return np.array( np.roll(self._rawdata_ch2, - (self._write_pointer_trigger + self._trigger_delay_register + 1)), - dtype=np.float) / 2 ** 13 + dtype=float) / 2 ** 13 @property def _data_ch1_current(self): """ (unnormalized) data from ch1 while acquisition is still running""" return np.array( np.roll(self._rawdata_ch1, -(self._write_pointer_current + 1)), - dtype=np.float) / 2 ** 13 + dtype=float) / 2 ** 13 @property def _data_ch2_current(self): """ (unnormalized) data from ch2 while acquisition is still running""" return np.array( np.roll(self._rawdata_ch2, -(self._write_pointer_current + 1)), - dtype=np.float) / 2 ** 13 + dtype=float) / 2 ** 13 @property def times(self): diff --git a/pyrpl/test/test_ipython_notebook/test_notebook.ipynb b/pyrpl/test/test_ipython_notebook/test_notebook.ipynb index 2a70afaaf..6b51cd2d9 100644 --- a/pyrpl/test/test_ipython_notebook/test_notebook.ipynb +++ b/pyrpl/test/test_ipython_notebook/test_notebook.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": true + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } }, "outputs": [], "source": [ @@ -14,9 +17,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], + "source": [ + "#define hostname\n", + "HOSTNAME = '_FAKE_'" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'python_sys_version'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[2], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01msys\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m sys\u001b[38;5;241m.\u001b[39mversion\u001b[38;5;241m==\u001b[39m\u001b[43mos\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43menviron\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpython_sys_version\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n", + "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\lib\\os.py:680\u001b[0m, in \u001b[0;36m_Environ.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 677\u001b[0m value \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_data[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mencodekey(key)]\n\u001b[0;32m 678\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m:\n\u001b[0;32m 679\u001b[0m \u001b[38;5;66;03m# raise KeyError with the original key value\u001b[39;00m\n\u001b[1;32m--> 680\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 681\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdecodevalue(value)\n", + "\u001b[1;31mKeyError\u001b[0m: 'python_sys_version'" + ] + } + ], "source": [ "import os\n", "import sys\n", @@ -25,9 +51,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\michael.croquette\\AppData\\Local\\miniconda3\\lib\\site-packages\\paramiko\\transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated\n", + " \"class\": algorithms.Blowfish,\n", + "WARNING:pyrpl.redpitaya:Simulating RedPitaya because (hostname==_FAKE_). Incomplete functionality possible. \n" + ] + } + ], "source": [ "from pyrpl import Pyrpl\n", "p = Pyrpl(hostname=HOSTNAME,\n", @@ -39,9 +75,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:pyrpl.modules:Register input1 of module scope has value 1, which does not correspond to selected option 10. Setting to 'in1'. \n" + ] + } + ], "source": [ "p.rp.scope.setup(duration=0.0001, trace_average=1)\n", "curve = p.rp.scope.single()\n", @@ -50,17 +94,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 5, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "a=2" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -74,9 +118,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.10.13" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }