Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate python3 #7

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4e92096
Create environment_pyrpl.yml
michaelcroquette Nov 14, 2023
5e6ae87
Update asg.py
michaelcroquette Nov 14, 2023
068ff4d
pg.GraphicsWindow is deprecated in pyqtgraph 0.13
michaelcroquette Apr 30, 2024
46b8562
Update environment_pyrpl.yml
michaelcroquette May 2, 2024
994c75d
np.complex and np.float deprecated
michaelcroquette May 2, 2024
33cb406
pg.GraphicsWindow -> pg.GraphicsLayoutWidget
michaelcroquette Jun 3, 2024
febcec0
Update environment_pyrpl.yml
michaelcroquette Jun 3, 2024
1f1be51
enable simple install
peteasa Oct 4, 2024
89b9b93
fixes for pyqt 2.4.1
peteasa Oct 5, 2024
31d1aab
Fixing float/int conversions and typing of numpy int/float which now …
danielbrown2 Oct 6, 2024
6c242cb
Fixes for the UI and async handling as these needed to be updated to …
danielbrown2 Oct 6, 2024
34bcf8e
fixes #505 where people were seeing divide by zero errors on initiali…
danielbrown2 Oct 6, 2024
2022a1c
fixing int conversions, parent setting
danielbrown2 Oct 6, 2024
8d2ec56
Update version for python3 support
peteasa Oct 7, 2024
dd60bfc
fixing errors in test code
peteasa Oct 6, 2024
c448215
bugfix memory reload
peteasa Oct 7, 2024
4e95c33
use concrete types to prevent numpy depreciated warnings
peteasa Oct 8, 2024
52def8e
Merge branch 'update_version_for_python3_support' into consolidate_py…
peteasa Oct 9, 2024
3e2b273
Merge branch 'python3-only' into consolidate_python3
peteasa Oct 9, 2024
6c104cf
Merge branch 'fix/async-ui-typing' into consolidate_python3
peteasa Oct 9, 2024
db898d3
Merge branch 'use_concrete_types' into consolidate_python3
peteasa Oct 9, 2024
6a4ae3b
Merge branch 'qtfixes' into consolidate_python3
peteasa Oct 9, 2024
9ac0bdb
use concrete types
peteasa Oct 9, 2024
bb8cdf8
Merge branch 'test_code' into consolidate_python3
peteasa Oct 9, 2024
cb80a3f
Merge branch 'bugfix_memory_reload' into consolidate_python3
peteasa Oct 9, 2024
e55b2b0
revert change. frequencies are used to size the tf array
peteasa Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added environment_pyrpl.yml
Binary file not shown.
4 changes: 3 additions & 1 deletion pyrpl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from ._version import __version_info__, __version__

import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))

__author__ = "Leonhard Neuhaus <[email protected]>"
__license__ = "MIT License"

Expand All @@ -25,7 +27,7 @@
try:
from IPython import get_ipython
IPYTHON = get_ipython()
IPYTHON.magic("gui qt")
IPYTHON.run_line_magic("gui", "qt")
except BaseException as e:
logger.debug('Could not enable IPython gui support: %s.' % e)

Expand Down
2 changes: 1 addition & 1 deletion pyrpl/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (0, 9, 6, 0)
__version_info__ = (1, 0, 0, 0)
__version__ = '.'.join(map(str, __version_info__))
86 changes: 55 additions & 31 deletions pyrpl/async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<ing functions:
the following functions:
* sleep(time_s): blocks the commandline for time_s, without blocking other
tasks such as gui update...
* wait(future, timeout=None): blocks the commandline until future is set or
Expand Down Expand Up @@ -36,18 +36,18 @@
import logging
from qtpy import QtCore, QtWidgets
import asyncio
from asyncio import Future, iscoroutine
import quamash
from asyncio import Future, iscoroutine, TimeoutError, get_event_loop, wait_for
import sys

import nest_asyncio
import qasync

logger = logging.getLogger(name=__name__)

# enable ipython QtGui support if needed
try:
from IPython import get_ipython
IPYTHON = get_ipython()
IPYTHON.magic("gui qt")
IPYTHON.run_line_magic("gui", "qt")
except BaseException as e:
logger.debug('Could not enable IPython gui support: %s.' % e)

Expand All @@ -57,25 +57,48 @@
APP = QtWidgets.QApplication(['pyrpl'])


LOOP = quamash.QEventLoop() # Since tasks scheduled in this loop seem to
# fall in the standard QEventLoop, and we never explicitly ask to run this
# loop, it might seem useless to send all tasks to LOOP, however, a task
# scheduled in the default loop seem to never get executed with IPython
# kernel integration.
LOOP = None # the main event loop
INTERACTIVE = True # True if we are in an interactive IPython session

try:
shell = get_ipython().__class__.__name__
if shell == 'ZMQInteractiveShell':
msg = 'async_utils: Jupyter notebook or qtconsole'
elif shell == 'TerminalInteractiveShell':
LOOP = qasync.QEventLoop(already_running=False)
INTERACTIVE = False
msg = 'async_utils: Terminal running IPython'
else:
LOOP = qasync.QEventLoop(already_running=False)
INTERACTIVE = False
msg = 'async_utils: # Other type (?)'
asyncio.events._set_running_loop(LOOP)
except NameError:
LOOP = qasync.QEventLoop(already_running=False)
INTERACTIVE = False
msg = 'async_utils: Probably standard Python interpreter'
asyncio.events._set_running_loop(LOOP)

logger.debug(msg)
if INTERACTIVE:
nest_asyncio.apply()

async def sleep_async(time_s):
"""
Replaces asyncio.sleep(time_s) inside coroutines. Deals properly with
IPython kernel integration.
"""
await asyncio.sleep(time_s, loop=LOOP)
await asyncio.sleep(time_s)

def ensure_future(coroutine):
"""
Schedules the task described by the coroutine. Deals properly with
IPython kernel integration.
"""
return asyncio.ensure_future(coroutine, loop=LOOP)
if INTERACTIVE:
return asyncio.ensure_future(coroutine)
else:
return asyncio.ensure_future(coroutine, loop=LOOP)

def wait(future, timeout=None):
"""
Expand All @@ -89,25 +112,26 @@ def curve(self):

BEWARE: never use wait in a coroutine (use builtin await instead)
"""
assert isinstance(future, Future) or iscoroutine(future)
new_future = ensure_future(asyncio.wait({future},
timeout=timeout,
loop=LOOP))
#if sys.version>='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()
timeout=timeout))

if INTERACTIVE:
new_future = wait_for(future, timeout)
loop = get_event_loop()
try:
return loop.run_until_complete(new_future)
except TimeoutError:
logger.error('async_utils wait: Timout exceeded')
else:
raise TimeoutError("Timout exceeded")
LOOP.run_until_complete(new_future)
done, pending = new_future.result()
if future in done:
return future.result()
else:
msg = 'async_utils wait: Timout exceeded'
logger.error(msg)
raise TimeoutError("Timout exceeded")


def sleep(time_s):
"""
Expand All @@ -122,7 +146,7 @@ class Event(asyncio.Event):
"""
Use this Event instead of asyncio.Event() to signal an event. This
version deals properly with IPython kernel integration.
Example: Resumng scope acquisition after a pause (acquisition_module.py)
Example: Resuming scope acquisition after a pause (acquisition_module.py)
def pause(self):
if self._running_state=='single_async':
self._running_state=='paused_single'
Expand All @@ -138,4 +162,4 @@ async def _single_async(self):
"""

def __init__(self):
super(Event, self).__init__(loop=LOOP)
super(Event, self).__init__()
7 changes: 6 additions & 1 deletion pyrpl/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,12 @@ def clog2(x):
return 32
else:
return int(np.floor(np.log2(float(x))))+1
return clog2(125000000.0/float(self._MINBW(obj)))
divider = float(self._MINBW(obj))

if divider == 0:
return clog2(125000000.0/10) # some default value to stop error, see issue #505
else:
return clog2(125000000.0/divider)

#def _ALPHABITS(self, obj):
# return int(np.ceil(np.log2(125000000.0 / self._MINBW(obj))))
Expand Down
4 changes: 2 additions & 2 deletions pyrpl/curvedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, name="some_curve"):
"""
self.logger = logging.getLogger(name=__name__)
self.params = dict()
x, y = np.array([], dtype=np.float), np.array([], dtype=np.float)
x, y = np.array([], dtype=np.float64), np.array([], dtype=np.float64)
self.data = (x, y)
self.name = name

Expand All @@ -80,7 +80,7 @@ def create(cls, *args, **kwds):
kwds will be passed to self.params
"""
if len(args) == 0:
ser = (np.array([], dtype=np.float), np.array([], dtype=np.float))
ser = (np.array([], dtype=np.float64), np.array([], dtype=np.float64))
if len(args) == 1:
if isinstance(args[0], pd.Series):
x, y = args[0].index.values, args[0].values
Expand Down
4 changes: 2 additions & 2 deletions pyrpl/hardware_modules/asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def data(self):
# self._reads(self._DATA_OFFSET, self.data_length),
# dtype=np.int32)
x[x >= 2 ** 13] -= 2 ** 14
return np.array(x, dtype=np.float) / 2 ** 13
return np.array(x, dtype=np.float64) / 2 ** 13

@data.setter
def data(self, data):
Expand All @@ -312,7 +312,7 @@ def data(self, data):
data = np.array(np.round((2 ** 13 - 1) * data), dtype=np.int32)
data[data >= 2 ** 13] = 2 ** 13 - 1
data[data < 0] += 2 ** 14
# values that are still negativeare set to maximally negatuve
# values that are still negative are set to maximally negative
data[data < 0] = -2 ** 13
data = np.array(data, dtype=np.uint32)
self._writes(self._DATA_OFFSET, data)
Expand Down
6 changes: 3 additions & 3 deletions pyrpl/hardware_modules/iir/iir.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ def transfer_function(self, frequencies, extradelay=0):

Returns
-------
tf: np.array(..., dtype=np.complex)
tf: np.array(..., dtype=np.complex128)
The complex open loop transfer function of the module.
If kind=='all', a list of plotdata tuples is returned that can be
passed directly to iir.bodeplot().
"""
# frequencies = np.array(frequencies, dtype=np.float)
# frequencies = np.array(frequencies, dtype=np.float64)
# take average delay to be half the loops since this is the
# expectation value for the delay (plus internal propagation delay)
# module_delay = self._delay + self.loops / 2.0
Expand Down Expand Up @@ -872,4 +872,4 @@ def format_coefs_verilog(self):
print("iir_coefficients[", 2*n, "]<=", -a1, ";")
n+=1
print("iir_coefficients[", 2*n, "]<=", -a2, ";")
n+=1
n+=1
18 changes: 9 additions & 9 deletions pyrpl/hardware_modules/iir/iir_theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def freqs(sys, w):

Returns
-------
np.array(..., dtype=np.complex) with the response
np.array(..., dtype=np.complex128) with the response
"""
z, p, k = sys
s = np.array(w, dtype=np.complex128) * 1j
Expand Down Expand Up @@ -135,7 +135,7 @@ def freqz_(sys, w, dt=8e-9):

Returns
-------
np.array(..., dtype=np.complex) with the response
np.array(..., dtype=complex) with the response
"""
z, p, k = sys
b, a = sig.zpk2tf(z, p, k)
Expand Down Expand Up @@ -877,7 +877,7 @@ def tf_inputfilter(self, inputfilter=None, frequencies=None): # input
inputfilter = self.inputfilter
if frequencies is None:
frequencies = self.frequencies
frequencies = np.asarray(frequencies, dtype=np.complex)
frequencies = np.asarray(frequencies, dtype=np.complex128)
try:
len(inputfilter)
except:
Expand Down Expand Up @@ -924,7 +924,7 @@ def tf_continuous(self, frequencies=None):
frequencies to compute the transfer function for
Returns
-------
np.array(..., dtype=np.complex)
np.array(..., dtype=np.complex128)
"""
if frequencies is None:
frequencies = self.frequencies
Expand All @@ -948,7 +948,7 @@ def tf_partialfraction(self, frequencies=None):

Returns
-------
np.array(..., dtype=np.complex)
np.array(..., dtype=np.complex128)
"""
# this code is more or less a direct copy of get_coeff()
if frequencies is None:
Expand Down Expand Up @@ -985,7 +985,7 @@ def tf_discrete(self, rp_discrete=None, frequencies=None):

Returns
-------
np.array(..., dtype=np.complex)
np.array(..., dtype=np.complex128)
"""
if frequencies is None:
frequencies = self.frequencies
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def tf_coefficients(self, frequencies=None, coefficients=None,

Returns
-------
np.array(..., dtype=np.complex)
np.array(..., dtype=np.complex128)
"""
if frequencies is None:
frequencies = self.frequencies
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def tf_rounded(self, frequencies=None, delay=False):

Returns
-------
np.array(..., dtype=np.complex)
np.array(..., dtype=np.complex128)
"""
return self.tf_coefficients(frequencies=frequencies,
coefficients=self.coefficients_rounded,
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def tf_final(self, frequencies=None):

Returns
-------
np.array(..., dtype=np.complex)
np.array(..., dtype=np.complex128)
"""
return self.tf_rounded(frequencies=frequencies, delay=True) * \
self.tf_inputfilter(frequencies=frequencies)
Expand Down
10 changes: 5 additions & 5 deletions pyrpl/hardware_modules/iq.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ def na_trace(
self._logger.info("Estimated acquisition time: %.1f s", float(avg + sleeptimes) * points / rbw)
sys.stdout.flush() # make sure the time is shown
# setup averaging
self._na_averages = np.int(np.round(125e6 / rbw * avg))
self._na_sleepcycles = np.int(np.round(125e6 / rbw * sleeptimes))
self._na_averages = np.int64(np.round(125e6 / rbw * avg))
self._na_sleepcycles = np.int64(np.round(125e6 / rbw * sleeptimes))
# compute rescaling factor
rescale = 2.0 ** (-self._LPFBITS) * 4.0 # 4 is artefact of fpga code
# obtained by measuring transfer function with bnc cable - could replace the inverse of 4 above
Expand Down Expand Up @@ -544,15 +544,15 @@ def transfer_function(self, frequencies, extradelay=0):

Returns
-------
tf: np.array(..., dtype=np.complex)
tf: np.array(..., dtype=np.complex128)
The complex open loop transfer function of the module.
"""
quadrature_delay = 2 # the delay experienced by the signal when it
# is represented as a quadrature (=lower frequency, less phaseshift)
# the remaining delay of the module
module_delay = self._delay - quadrature_delay
frequencies = np.array(frequencies, dtype=np.complex)
tf = np.array(frequencies * 0, dtype=np.complex) + self.gain
frequencies = np.array(frequencies, dtype=np.complex128)
tf = np.array(frequencies * 0, dtype=np.complex128) + self.gain
# bandpass filter
for f in self.bandwidth:
if f == 0:
Expand Down
4 changes: 2 additions & 2 deletions pyrpl/hardware_modules/pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def transfer_function(self, frequencies, extradelay=0):

Returns
-------
tf: np.array(..., dtype=np.complex)
tf: np.array(..., dtype=np.complex128)
The complex open loop transfer function of the module.
"""
return Pid._transfer_function(frequencies,
Expand Down Expand Up @@ -429,7 +429,7 @@ def _pid_transfer_function(cls,
found in pid._frequency_correction
"""

frequencies = np.array(frequencies, dtype=complex)
frequencies = np.array(frequencies, dtype=np.complex128)
# integrator with one cycle of extra delay
tf = i / (frequencies * 1j) \
* np.exp(-1j * 8e-9 * frequency_correction *
Expand Down
Loading