Skip to content

Commit

Permalink
Merge 2c20a47 into f4e4b91
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Sep 5, 2018
2 parents f4e4b91 + 2c20a47 commit a801b6b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ before_install:
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pip atlas numpy matplotlib
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pip atlas numpy matplotlib gmpy2
- source activate test-environment
- pip install pyflakes coverage coveralls sympy
install:
Expand Down
19 changes: 8 additions & 11 deletions qctoolkit/_program/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from collections import defaultdict, deque
from copy import deepcopy
from enum import Enum
from fractions import Fraction
import warnings

import numpy as np
Expand Down Expand Up @@ -122,14 +121,12 @@ def repetition_count(self, val) -> None:
def unroll(self) -> None:
if self.is_leaf():
raise RuntimeError('Leaves cannot be unrolled')
for i, e in enumerate(self.parent):
if id(e) == id(self):
self.parent[i:i+1] = (child.copy_tree_structure(new_parent=self.parent)
for _ in range(self.repetition_count)
for child in self)
self.parent.assert_tree_integrity()
return
raise Exception('self not found in parent')

i = self.parent_index
self.parent[i:i+1] = (child.copy_tree_structure(new_parent=self.parent)
for _ in range(self.repetition_count)
for child in self)
self.parent.assert_tree_integrity()

def __setitem__(self, idx, value):
super().__setitem__(idx, value)
Expand Down Expand Up @@ -522,7 +519,7 @@ def _is_compatible(program: Loop, min_len: int, quantum: int, sample_rate: TimeT
return _CompatibilityLevel.action_required


def _make_compatible(program: Loop, min_len: int, quantum: int, sample_rate: Fraction) -> None:
def _make_compatible(program: Loop, min_len: int, quantum: int, sample_rate: TimeType) -> None:

if program.is_leaf():
program.waveform = to_waveform(program.copy_tree_structure())
Expand All @@ -549,7 +546,7 @@ def _make_compatible(program: Loop, min_len: int, quantum: int, sample_rate: Fra
_make_compatible(sub_program, min_len, quantum, sample_rate)


def make_compatible(program: Loop, minimal_waveform_length: int, waveform_quantum: int, sample_rate: Fraction):
def make_compatible(program: Loop, minimal_waveform_length: int, waveform_quantum: int, sample_rate: TimeType):
comp_level = _is_compatible(program,
min_len=minimal_waveform_length,
quantum=waveform_quantum,
Expand Down
1 change: 0 additions & 1 deletion qctoolkit/_program/waveforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Union, Set, Sequence, NamedTuple, Tuple, Any, Iterable, FrozenSet, Optional

import numpy as np
import pandas as pd

from qctoolkit import ChannelID
from qctoolkit.utils import checked_int_cast
Expand Down
2 changes: 1 addition & 1 deletion qctoolkit/pulses/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _render_instruction_block(sequence: AbstractInstructionBlock,
sample_count = total_time * sample_rate + 1
if not float(sample_count).is_integer():
warnings.warn('Sample count not whole number. Casted to integer.')
times = np.linspace(0, total_time, num=int(sample_count), dtype=float)
times = np.linspace(0, float(total_time), num=int(sample_count), dtype=float)
# move the last sample inside the waveform
times[-1] = np.nextafter(times[-1], times[-2])

Expand Down
4 changes: 4 additions & 0 deletions qctoolkit/utils/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def children(self: _NodeType) -> List[_NodeType]:
def parent(self: _NodeType) -> Union[None, _NodeType]:
return self.__parent()

@property
def parent_index(self) -> int:
return self.__parent_index

def get_root(self: _NodeType) -> _NodeType:
if self.parent:
return self.parent.get_root()
Expand Down
7 changes: 4 additions & 3 deletions qctoolkit/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import abc
import inspect
import numbers
import fractions
import gmpy2

import numpy

Expand All @@ -11,11 +11,12 @@

MeasurementWindow = typing.Tuple[str, numbers.Real, numbers.Real]
ChannelID = typing.Union[str, int]
TimeType = fractions.Fraction
TimeType = gmpy2.mpq


def time_from_float(time: float, absolute_error: float=1e-12) -> TimeType:
return fractions.Fraction(time).limit_denominator(int(1/absolute_error))
# gmpy2 is at least an order of magnitude faster than fractions.Fraction
return gmpy2.mpq(gmpy2.f2q(time, absolute_error))


class DocStringABCMeta(abc.ABCMeta):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package_dir={'qctoolkit': 'qctoolkit'},
packages=packages,
tests_require=['pytest'],
install_requires=['sympy>=1.1.1', 'numpy', 'pandas', 'cached_property'] + requires_typing,
install_requires=['sympy>=1.1.1', 'numpy', 'cached_property', 'gmpy2'] + requires_typing,
extras_require={
'testing': ['pytest'],
'plotting': ['matplotlib'],
Expand Down
13 changes: 5 additions & 8 deletions tests/_program/transformation_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest
from unittest import mock

import pandas as pd
import numpy as np

from qctoolkit._program.transformation import LinearTransformation, Transformation, IdentityTransformation,\
Expand Down Expand Up @@ -146,9 +145,7 @@ def test_singleton(self):

def test_call(self):
time = np.arange(12)
data = (np.arange(12.) + 1).reshape((3, 4))
data = pd.DataFrame(data, index=list('abc'))

data = dict(zip('abc',(np.arange(12.) + 1).reshape((3, 4))))
self.assertIs(IdentityTransformation()(time, data), data)

def test_output_channels(self):
Expand Down Expand Up @@ -210,10 +207,10 @@ def test_call(self):
time = np.arange(12)
data = (np.arange(12.) + 1).reshape((3, 4))

data_in = pd.DataFrame(data, index=list('abc'))
data_0 = data_in + 42
data_1 = data_0 + 42
data_2 = data_1 + 42
data_in = dict(zip('abc', data))
data_0 = dict(zip('abc', data + 42))
data_1 = dict(zip('abc', data + 2*42))
data_2 = dict(zip('abc', data + 3*42))
with mock.patch('tests._program.transformation_tests.TransformationStub.__call__',
side_effect=[data_0, data_1, data_2]) as call:
outs = chained(time, data_in)
Expand Down

0 comments on commit a801b6b

Please sign in to comment.