Skip to content

Commit

Permalink
Merge 4fed1e2 into f378ef2
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Mar 17, 2021
2 parents f378ef2 + 4fed1e2 commit 3784e21
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 60 deletions.
2 changes: 1 addition & 1 deletion qupulse/hardware/awgs/tektronix.py
Expand Up @@ -609,7 +609,7 @@ def _upload_linked_sequencing_elements(self,
if previous_errors:
self.logger.warning("Error queue not empty before sequence upload: %r", previous_errors)

positions_with_next = pairwise(positions, fillvalue=last_jump_to)
positions_with_next = pairwise(positions, zip_function=itertools.zip_longest, fillvalue=last_jump_to)

self._synchronized = False
for idx, ((element_index, next_element), sequencing_element) in enumerate(zip(positions_with_next, sequencing_elements)):
Expand Down
3 changes: 1 addition & 2 deletions qupulse/hardware/feature_awg/base.py
@@ -1,10 +1,9 @@
from abc import ABC, abstractmethod
from typing import Optional
from typing import Optional, Collection
import weakref

from qupulse.hardware.awgs.base import AWG
from qupulse.hardware.feature_awg.base_features import Feature, FeatureAble
from qupulse.utils.types import Collection

__all__ = ["AWGDevice", "AWGChannelTuple", "AWGChannel", "AWGMarkerChannel", "AWGDeviceFeature", "AWGChannelFeature",
"AWGChannelTupleFeature"]
Expand Down
5 changes: 3 additions & 2 deletions qupulse/hardware/feature_awg/tabor.py
Expand Up @@ -3,7 +3,8 @@
import numbers
import sys
import weakref
from typing import List, Tuple, Set, Callable, Optional, Any, cast, Union, Dict, Mapping, NamedTuple, Iterable
from typing import List, Tuple, Set, Callable, Optional, Any, cast, Union, Dict, Mapping, NamedTuple, Iterable,\
Collection
from collections import OrderedDict
import numpy as np
from qupulse import ChannelID
Expand All @@ -15,7 +16,7 @@
ReadProgram, RepetitionMode
from qupulse.hardware.util import voltage_to_uint16, find_positions

from qupulse.utils.types import Collection, TimeType
from qupulse.utils.types import TimeType
from qupulse.hardware.feature_awg.base import AWGChannelTuple, AWGChannel, AWGDevice, AWGMarkerChannel
from typing import Sequence
from qupulse._program.tabor import TaborSegment, TaborException, TaborProgram, PlottableProgram, TaborSequencing, \
Expand Down
4 changes: 2 additions & 2 deletions qupulse/hardware/util.py
@@ -1,10 +1,10 @@
from typing import List, Sequence, Tuple, Union
from typing import List, Sequence, Tuple, Union, Collection
import itertools

import numpy as np

from qupulse._program.waveforms import Waveform
from qupulse.utils.types import TimeType, Collection
from qupulse.utils.types import TimeType
from qupulse.utils import pairwise

__all__ = ['voltage_to_uint16', 'get_sample_times']
Expand Down
6 changes: 3 additions & 3 deletions qupulse/pulses/table_pulse_template.py
Expand Up @@ -15,8 +15,8 @@
import numpy as np
import sympy
from sympy.logic.boolalg import BooleanAtom
import more_itertools

from qupulse.utils import pairwise
from qupulse.utils.types import ChannelID
from qupulse.serialization import Serializer, PulseRegistryType
from qupulse.pulses.parameters import Parameter, \
Expand Down Expand Up @@ -75,7 +75,7 @@ def _sequence_integral(cls, entry_sequence: Sequence['TableEntry'],
Scalar expression for the integral.
"""
expr = 0
for first_entry, second_entry in more_itertools.pairwise(entry_sequence):
for first_entry, second_entry in pairwise(entry_sequence):
substitutions = {'t0': first_entry.t.sympified_expression,
'v0': expression_extractor(first_entry.v),
't1': second_entry.t.sympified_expression,
Expand Down Expand Up @@ -113,7 +113,7 @@ def _sequence_as_expression(cls, entry_sequence: Sequence['TableEntry'],
if post_value is not None:
piecewise_args.append((post_value, t >= entry_sequence[-1].t.sympified_expression))

for first_entry, second_entry in more_itertools.pairwise(entry_sequence):
for first_entry, second_entry in pairwise(entry_sequence):
t0, t1 = first_entry.t.sympified_expression, second_entry.t.sympified_expression
substitutions = {'t0': t0,
'v0': expression_extractor(first_entry.v),
Expand Down
8 changes: 4 additions & 4 deletions qupulse/utils/__init__.py
@@ -1,6 +1,6 @@
"""This package contains utility functions and classes as well as custom sympy extensions(hacks)."""

from typing import Union, Iterable, Any, Tuple, Mapping
from typing import Union, Iterable, Any, Tuple, Mapping, Iterator, cast
import itertools
import re
import numbers
Expand Down Expand Up @@ -44,20 +44,20 @@ def _fallback_is_close(a, b, *, rel_tol=1e-09, abs_tol=0.0):


def pairwise(iterable: Iterable[Any],
zip_function=itertools.zip_longest, **kwargs) -> Iterable[Tuple[Any, Any]]:
zip_function=zip, **kwargs) -> Iterator[Tuple[Any, Any]]:
"""s -> (s0,s1), (s1,s2), (s2, s3), ...
Args:
iterable: Iterable to iterate over pairwise
zip_function: Either zip or itertools.zip_longest(default)
zip_function: Either zip(default) or itertools.zip_longest
**kwargs: Gets passed to zip_function
Returns:
An iterable that yield neighbouring elements
"""
a, b = itertools.tee(iterable)
next(b, None)
return zip_function(a, b, **kwargs)
return cast(Iterator[Tuple[Any, Any]], zip_function(a, b, **kwargs))


def grouper(iterable: Iterable[Any], n: int, fillvalue=None) -> Iterable[Tuple[Any, ...]]:
Expand Down
32 changes: 0 additions & 32 deletions qupulse/utils/types.py
Expand Up @@ -377,38 +377,6 @@ def has_type_interface(obj: typing.Any, type_obj: typing.Type) -> bool:
return set(dir(obj)) >= {attr for attr in dir(type_obj) if not attr.startswith('_')}


if hasattr(typing, 'Collection'):
Collection = typing.Collection
else:
def _check_methods(C, *methods):
"""copied from https://github.com/python/cpython/blob/3.8/Lib/_collections_abc.py"""
mro = C.__mro__
for method in methods:
for B in mro:
if method in B.__dict__:
if B.__dict__[method] is None:
return NotImplemented
break
else:
return NotImplemented
return True

class _ABCCollection(collections.abc.Sized, collections.abc.Iterable, collections.abc.Container):
"""copied from https://github.com/python/cpython/blob/3.8/Lib/_collections_abc.py"""
__slots__ = ()

@classmethod
def __subclasshook__(cls, C):
# removed "if cls is _ABCCollection" guard because reloading this module damages the test
return _check_methods(C, "__len__", "__iter__", "__contains__")

class Collection(typing.Sized, typing.Iterable[typing.T_co], typing.Container[typing.T_co],
extra=_ABCCollection):
"""Fallback for typing.Collection if python 3.5
copied from https://github.com/python/cpython/blob/3.5/Lib/typing.py"""
__slots__ = ()


_KT_hash = typing.TypeVar('_KT_hash', bound=typing.Hashable) # Key type.
_T_co_hash = typing.TypeVar('_T_co_hash', bound=typing.Hashable, covariant=True) # Any type covariant containers.

Expand Down
6 changes: 4 additions & 2 deletions tests/_program/seqc_tests.py
Expand Up @@ -5,6 +5,7 @@
import sys
import tempfile
import pathlib
import hashlib

import numpy as np

Expand Down Expand Up @@ -51,7 +52,8 @@ def get_unique_wfs(n=10000, duration=32, defined_channels=frozenset(['A'])):
key = (n, duration)

if key not in get_unique_wfs.cache:
h = hash(key)
# positive deterministic int64
h = int(hashlib.sha256(str(key).encode('ascii')).hexdigest()[:2*8], base=16) // 2
base = np.bitwise_xor(np.linspace(-h, h, num=duration + n, dtype=np.int64), h)
base = base / np.max(np.abs(base))

Expand Down Expand Up @@ -768,7 +770,7 @@ def test_full_run(self):
const PROG_SEL_MASK = 0b111111111111111111111111111111;
const INVERTED_PROG_SEL_MASK = 0b11000000000000000000000000000000;
const IDLE_WAIT_CYCLES = 300;
wave test_concatenated_waveform_0 = "3e0090e8ffd002d1134ce38827c6a35fede89cf23d126a44057ef43f466ae4cd";
wave test_concatenated_waveform_0 = "c583e709957ec1536986ae1c7a6ad6311c89e052405d2a5c786760fc2fcdf6e3";
wave test_shared_waveform_121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518 = "121f5c6e8822793b3836fb3098fa4591b91d4c205cc2d8afd01ee1bf6956e518";
// function used by manually triggered programs
Expand Down
3 changes: 1 addition & 2 deletions tests/hardware/feature_awg/awg_new_driver_base_tests.py
@@ -1,4 +1,4 @@
from typing import Callable, Iterable, Optional, Set, Tuple
from typing import Callable, Iterable, Optional, Set, Tuple, Collection
import unittest
import warnings

Expand All @@ -8,7 +8,6 @@
from qupulse.hardware.feature_awg.base import AWGDevice, AWGChannel, AWGChannelTuple, AWGMarkerChannel
from qupulse.hardware.feature_awg.features import ChannelSynchronization, ProgramManagement, VoltageRange, \
AmplitudeOffsetHandling, RepetitionMode, VolatileParameters
from qupulse.utils.types import Collection


########################################################################################################################
Expand Down
11 changes: 1 addition & 10 deletions tests/utils/types_tests.py
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from qupulse.utils.types import (HashableNumpyArray, Collection, SequenceProxy, _FrozenDictByWrapping,
from qupulse.utils.types import (HashableNumpyArray, SequenceProxy, _FrozenDictByWrapping,
_FrozenDictByInheritance)


Expand All @@ -20,15 +20,6 @@ def test_hash(self):
self.assertEqual(hash(a), hash(c))


class CollectionTests(unittest.TestCase):
def test_isinstance(self):
self.assertTrue(isinstance(set(), Collection))
self.assertTrue(isinstance(list(), Collection))
self.assertTrue(isinstance(tuple(), Collection))

self.assertFalse(isinstance(5, Collection))


class SequenceProxyTest(unittest.TestCase):
def test_sequence_proxy(self):
l = [1, 2, 3, 4, 1]
Expand Down

0 comments on commit 3784e21

Please sign in to comment.