Skip to content

Commit 70aa732

Browse files
committed
fix import error
1 parent d79b688 commit 70aa732

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

qupulse/pulses/method_pulse_template.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import (Any, Callable, Dict, List, Optional, Set, Union)
33

44
import numpy as np
5-
import scipy.integrate
65
from qupulse._program.waveforms import MethodWaveform
76
from qupulse.expressions import ExpressionScalar
87
from qupulse.pulses.measurement import MeasurementDeclaration
@@ -117,6 +116,11 @@ def deserialize(cls,
117116

118117
@property
119118
def integral(self) -> Dict[ChannelID, ExpressionScalar]:
119+
try:
120+
import scipy.integrate
121+
except ImportError:
122+
raise ValueError(f'scipy package is required to perform integral calculations for {self.__class__}')
123+
120124
return {self.__channel: ExpressionScalar(scipy.integrate.quad(self._pulse_method, 0, float(self.duration))[0]
121125
)}
122126

tests/pulses/method_pulse_tests.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def test_duration(self):
2424
self.assertEqual(self.fpt.duration, 100)
2525

2626
def test_integral(self) -> None:
27+
try:
28+
import scipy.integrate
29+
except ImportError:
30+
return
31+
2732
pulse = MethodPulseTemplate(pulse_method=lambda t: 0*t, duration=30)
2833
self.assertDictEqual(pulse.integral, {'default': 0})
2934
pulse = MethodPulseTemplate(pulse_method=lambda t: 1+0*t, duration=30)

0 commit comments

Comments
 (0)