• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qutech / qupulse / 16672493391

01 Aug 2025 10:15AM UTC coverage: 88.761%. First build
16672493391

Pull #917

github

web-flow
Merge 19e71ade7 into a8a829612
Pull Request #917: Experiment followup dlv

134 of 141 new or added lines in 2 files covered. (95.04%)

18915 of 21310 relevant lines covered (88.76%)

5.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.59
/tests/program/values_tests.py
1
import copy
6✔
2
import unittest
6✔
3
from unittest import TestCase
6✔
4

5
import numpy as np
6✔
6

7
from qupulse.pulses import *
6✔
8
from qupulse.program.linspace import *
6✔
9
from qupulse.program.transformation import *
6✔
10
from qupulse.pulses.function_pulse_template import FunctionPulseTemplate
6✔
11
from qupulse.program.values import DynamicLinearValue, ResolutionDependentValue, DynamicLinearValueStepped
6✔
12
from qupulse.utils.types import TimeType
6✔
13

14

15
class DynamicLinearValueTests(TestCase):
6✔
16
    def setUp(self):
6✔
17
        self.d = DynamicLinearValue(-100,{'a':np.pi,'b':np.e})
6✔
18
        self.d3 = DynamicLinearValue(-300,{'a':np.pi,'b':np.e})
6✔
19
    
20
    def test_value(self):
6✔
21
        dval = self.d.value({'a':12,'b':34})
6✔
22
        np.testing.assert_allclose(dval, 12*np.pi+34*np.e-100)
6✔
23
        
24
    # def test_abs(self):
25
    #     np.testing.assert_allclose(abs(self.d),100+np.pi+np.e)
26
    
27
    def test_add_sub_neg(self):
6✔
28

29
        self.assertEqual(self.d + 3,
6✔
30
                         DynamicLinearValue(-100+3,{'a':np.pi,'b':np.e}))
31
        self.assertEqual(self.d + np.pi,
6✔
32
                         DynamicLinearValue(-100+np.pi,{'a':np.pi,'b':np.e}))
33
        self.assertEqual(self.d + TimeType(12/5),
6✔
34
                         DynamicLinearValue(-100+TimeType(12/5),{'a':np.pi,'b':np.e}))
35
        #sub
36
        self.assertEqual(self.d - TimeType(12/5),
6✔
37
                         DynamicLinearValue(-100-TimeType(12/5),{'a':np.pi,'b':np.e}))
38
        
39
        #this would raise because of TimeType conversion
40
        # self.assertEqual(TimeType(12/5)-self.d,
41
        #                  DynamicLinearValue(100+TimeType(12/5),{'a':-np.pi,'b':-np.e}))
42
        #same type
43
        self.assertEqual(self.d+DynamicLinearValue(0.1,{'b':1,'c':2}),
6✔
44
                         DynamicLinearValue(-99.9,{'a':np.pi,'b':np.e+1,'c':2}))
45
    
46
    def test_mul(self):
6✔
47
        self.assertEqual(self.d*3,
6✔
48
                         DynamicLinearValue(-3*100,{'a':3*np.pi,'b':3*np.e}))
49
        self.assertEqual(3*self.d,
6✔
50
                         DynamicLinearValue(-3*100,{'a':3*np.pi,'b':3*np.e}))
51
        #div
52
        self.assertEqual(self.d3/3,
6✔
53
                         DynamicLinearValue(-100,{'a':np.pi/3,'b':np.e/3}))
54
        #raise
55
        self.assertRaises(TypeError,lambda: 3/self.d,)
6✔
56
    
57
    def test_eq(self):
6✔
58
        
59
        self.assertEqual(self.d==1,False)
6✔
60
        self.assertEqual(self.d==1+1j,False)
6✔
61
        # self.assertEqual(self.d>-101,True) #if one wants to allow these comparisons
62
        # self.assertEqual(self.d<TimeType(24/5),True)  #if one wants to allow these comparisons
63
        
64
        self.assertEqual(self.d==self.d,True)
6✔
65
        self.assertEqual(self.d+1==self.d,False)
6✔
66
        
67
        # inoperative features.
68
        # self.assertEqual(self.d+1>self.d,False)
69
        # self.assertEqual(self.d+1<self.d,False)
70
        # self.assertEqual(self.d+1>=self.d,True)
71
        # self.assertEqual(self.d+1<=self.d,False)
72
        
73
        # self.assertEqual(self.d>self.d/2-51,True)
74
        # self.assertEqual(self.d<self.d*2+101,True)
75
        
76
    def test_sympy(self):
6✔
77
        self.assertEqual(self.d._sympy_(), self.d)
6✔
78
        self.assertEqual(self.d.replace(1,1), self.d)
6✔
79
        
80
    def test_hash(self):
6✔
81
        self.assertEqual(hash(self.d), hash(self.d))
6✔
82
        self.assertNotEqual(hash(self.d), hash(self.d3))
6✔
83
        
84
        
85

86
class ResolutionDependentValueTests(TestCase):
6✔
87
    def setUp(self):
6✔
88
        self.d = ResolutionDependentValue((np.pi*1e-5,np.e*1e-5),(10,20),0.1)
6✔
89
        self.d2 = ResolutionDependentValue((np.e*1e-5,np.pi*1e-5),(10,20),-0.1)
6✔
90
        self.dtt = ResolutionDependentValue((TimeType(12,5),TimeType(14,5)),(10,20),TimeType(12,5))
6✔
91
        self.dint = ResolutionDependentValue((1,2),(10,20),1)
6✔
92
        
93
        self._default_res = 2**-16
6✔
94
        
95
    def test_call(self):
6✔
96
        val = self.d(self._default_res)
6✔
97
        #expected to round to 2*res each, so 60*2**16, offset also rounded
98
        expected_val = 2**-16 * 60 + 0.100006103515625
6✔
99
        self.assertAlmostEqual(val,expected_val,places=12)
6✔
100
        self.assertEqual((val/self._default_res)%1,0)
6✔
101
        
102
        #if no resolution must be tt or int
103
        self.assertEqual(self.dtt(None),TimeType(412, 5))
6✔
104
        self.assertEqual(self.dint(None),51)
6✔
105
        
106
    def test_dunder(self):
6✔
107
        self.assertEqual(bool(self.d), True)
6✔
108
        self.assertRaises(TypeError, lambda: self.d+self.d2)
6✔
109
        self.assertEqual(self.d-0.1,
6✔
110
                         ResolutionDependentValue((np.pi*1e-5,np.e*1e-5),(10,20),0.0))
111
        self.assertEqual(self.d*2,
6✔
112
                         ResolutionDependentValue((np.pi*1e-5*2,np.e*1e-5*2),(10,20),0.2))
113
        self.assertEqual(self.d/2,
6✔
114
                         ResolutionDependentValue((np.pi*1e-5/2,np.e*1e-5/2),(10,20),0.1/2)) 
115
        
116
        self.assertRaises(AssertionError, lambda: float(self.d))
6✔
117
        
118
        try: str(self.d)
6✔
NEW
119
        except: self.fail()
×
120
        
121
        self.assertEqual(hash(self.d), hash(self.d))
6✔
122
        self.assertNotEqual(hash(self.d), hash(self.d2))
6✔
123
        
124
        self.assertEqual(self.d==ResolutionDependentValue((np.pi*1e-5,np.e*1e-5),(10,20),0.1),True)
6✔
125
        
126
        
127
class DynamicLinearValueSteppedTests(TestCase):
6✔
128
    def test_properties(self):
6✔
129
        d = DynamicLinearValueStepped(0.,{'a':1},1,range(3),False)
6✔
130
        self.assertEqual(d.rng, range(3))
6✔
131
        self.assertEqual(d.step_nesting_level, 1)
6✔
132
        self.assertEqual(d.reverse, False)
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc