class Fitter(LineFitter): Ejmax=FloatRange(0.001, 100.0, 40.0).tag(tracking=True) offset=FloatRange(0.0, 100.0, 18.0).tag(tracking=True) @tag_property(private=True) def data(self): return a._get_flux_parabola(voltage=linspace(-1,1,100), offset=self.offset, Ejmax=self.Ejmax*h)
class ViewerLight(Atom): """ A Light in the view """ #: Whether the light is on enabled = Bool(True) #: Type of light type = Enum("directional", "spot", "ambient") #: Color of the light source color = ColorMember() #: Name of the light name = Str() #: Intensity of light source intensity = FloatRange(0.0, 1.0, 1.0) # ------------------------------------------------------------------------ # Directional light parameters # ------------------------------------------------------------------------ orientation = Enum( 'XnegYnegZneg', 'Xpos', 'Ypos', 'Zpos', 'Xneg', 'Yneg', 'Zneg', 'XposYpos', 'XposZpos', 'YposZpos', 'XnegYneg', 'XnegYpos', 'XnegZneg', 'XnegZpos', 'YnegZneg', 'YnegZpos', 'XposYneg', 'XposZneg', 'YposZneg', 'XposYposZpos', 'XposYnegZpos', 'XposYposZneg', 'XnegYposZpos', 'XposYnegZneg', 'XnegYposZneg', 'XnegYnegZpos', 'Zup_AxoLeft', 'Zup_AxoRight', 'Zup_Front', 'Zup_Back', 'Zup_Top', 'Zup_Bottom', 'Zup_Left', 'Zup_Right', 'Yup_AxoLeft', 'Yup_AxoRight', 'Yup_Front', 'Yup_Back', 'Yup_Top', 'Yup_Bottom', 'Yup_Left', 'Yup_Right') #: Headlight flag means that light position/direction are defined not in a #: World coordinate system, but relative to the camera orientation headlight = Bool() # ------------------------------------------------------------------------ # Spot light parameters # ------------------------------------------------------------------------ #: Position of the spot light position = Typed(Point) #: Direction of the spot light direction = Typed(Direction) def _default_direction(self): return Direction(-1, -1, -1) #: Range of the light source, 0.0 means infininte range = Float(0.0, strict=False) # Angle in radians of the cone created by the spot angle = FloatRange(0.0, math.pi, math.pi / 2)
class Fitter(Operative): offset=FloatRange(-1.0, 1.0, qdt.offset).tag(tracking=True) flux_factor=FloatRange(0.01, 1.0, qdt.flux_factor).tag(tracking=True) extra_atten=FloatRange(0.0, 30.0, 0.0).tag(tracking=True) #pwr=Array() @tag_Property(plot=True, private=True) def PdBm_from_Ic(self): flux_over_flux0=(a.yoko-self.offset)*self.flux_factor Ej=qdt.Ejmax*absolute(cos(pi*flux_over_flux0)) I=Ej*(2.0*e)/hbar mu_q=0.8*qdt.K2*qdt.Np gm=2*mu_q*qdt.W*qdt.epsinf*2*pi*qdt.f0/qdt.K2 phi=I/gm #=gm*phi mu=0.8*qdt.K2*idt.Np V=phi/mu Pwatts=(V**2)/50.0 PdBm=10.0*log10(Pwatts/0.001)+self.extra_atten return PdBm #pwr=a.pwr-a.rt_atten-a.fridge_atten #Pwatts=0.001*10.0**(pwr/10.0) #V=sqrt(Pwatts*50.0) @tag_Property(plot=True, private=True) def flux_parabola(self): flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=self.offset, flux_factor=self.flux_factor) Ej=qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) return qdt._get_fq(Ej, qdt.Ec) #return qdt.flux_parabola(voltage=self.yoko, offset=self.offset, flux_factor=self.flux_factor) yoko=Array().tag(unit="V", plot=True, label="Yoko", private=True) plotter=Typed(Plotter).tag(private=True) @observe("offset", "flux_factor", "extra_atten") def update_plot(self, change): if change["type"]=="update": if "flux_parabola" in self.plotter.plot_dict: self.get_member("flux_parabola").reset(self) self.plotter.plot_dict["flux_parabola"].clt.set_ydata(self.flux_parabola) if "PdBm_from_Ic" in self.plotter.plot_dict: self.get_member("PdBm_from_Ic").reset(self) self.plotter.plot_dict["PdBm_from_Ic"].clt.set_ydata(self.PdBm_from_Ic) self.plotter.draw()
class Fitter1(Fitter): offset=FloatRange(-1.0, 1.0, -0.036).tag(tracking=True) flux_factor=FloatRange(0.01, 1.0, qdt.flux_factor).tag(tracking=True) @tag_Property(plot=True, private=True) def flux_parabola(self): return qdt.call_func("flux_parabola", voltage=a.yoko, offset=self.offset, flux_factor=self.flux_factor, Ec=qdt.Ec) @observe("offset", "flux_factor") def update_plot(self, change): if change["type"]=="update": self.get_member("flux_parabola").reset(self) b.plot_dict["magabs_flux"].clt.set_xdata(self.flux_parabola*1e-9) b.draw()
class Fitter(Atom): a = FloatRange(0.0, 10.0, 1.0) b = Float(2.0).tag(low=0.0, high=10.0) figure = Typed(Figure) fit_line = Typed(Line2D) def _default_fit_line(self): return plot(self.xfit, self.yfit)[0] def _default_figure(self): return self.fit_line.figure @cached_property def xfit(self): return linspace(0, 4, 20) @cached_property def yfit(self): return self.b * self.xfit + self.a @observe("a", "b") def change_parameters(self, change): if change["type"] == "update": self.get_member("yfit").reset(self) self.fit_line.set_ydata(self.yfit) self.draw() def autoscale_y(self): ylim(min(min(self.yfit), ymin), max(max(self.yfit), ymax)) self.draw() def draw(self): if self.figure.canvas != None: self.figure.canvas.draw()
class PlotView(Control): hug_width = set_default('ignore') hug_height = set_default('ignore') proxy = Typed(ProxyPlotView) data = d_(ContainerList()) setup = d_(Callable(lambda graph: None)) title = d_(Str()) labels = d_(Dict(Str(), Str())) axis_scales = d_(Dict(Str(), Float())) #background_color = d_(Str()) #foreground = d_(Str()) antialiasing = d_(Bool(True)) aspect_locked = d_(Bool(True)) grid = d_(Tuple(item=Bool(), default=(False, False))) grid_alpha = d_(FloatRange(low=0.0, high=1.0, value=0.5)) multi_axis = d_(Bool(True)) @observe('data', 'title', 'labels', 'multi_axis', 'antialiasing', 'axis_scales', 'grid', 'grid_alpha') def _update_proxy(self, change): """ An observer which sends state change to the proxy. """ # The superclass handler implementation is sufficient. super(PlotView, self)._update_proxy(change)
class Fitter(LineFitter2): Np = Float(a.idt.Np) #.tag(tracking=True) f0 = Float(a.idt.f0 / 1e9) #.tag(tracking=True) loss = Float(-11.0) #.tag(tracking=True) L = FloatRange(400.0, 600.0, 500.0).tag(tracking=True) dloss = Float(0.0) C = Float(a.idt.C) K2 = Float(a.idt.K2) dL = Float(a.idt.dL) def _default_plotter(self): line(*self.data, plot_name=self.plot_name, plotter=pl, color="green", linewidth=0.3, alpha=0.6) return pl def _default_plot_name(self): return "myplot" @tag_property(private=True) def data(self): return a.frequency, 10 * log10( absolute( a.idt._get_S33(f=a.frequency, f0=self.f0 * 1e9, Np=self.Np, C=self.C, K2=self.K2, dL=self.dL))) + self.loss
class Fitter2(Fitter): frequency=FloatRange(4.4, 4.5, 4.4622).tag(tracking=True) offset=FloatRange(0.00, 1.0e-2, 0.0).tag(tracking=True) height=FloatRange(0.00, 1.0e-2, 0.0).tag(tracking=True) width=FloatRange(10.0, 500.0, 50.0).tag(tracking=True) @tag_Property(plot=True, private=True) def lorenz(self): return lorentzian(c.flux_parabola, [self.width*1e6, self.frequency*1e9, self.height, self.offset]) @observe("frequency", "offset", "width", "height") def update_plot(self, change): if change["type"]=="update": self.get_member("lorenz").reset(self) b.plot_dict["lorenz"].clt.set_ydata(self.lorenz) b.draw()
class Fitter3(Operative): base_name="fitter" mult=FloatRange(0.001, 5.0, 0.82).tag(tracking=True) f0=FloatRange(4.0, 6.0, 5.348).tag(tracking=True) offset=FloatRange(0.0, 100.0, 18.0).tag(tracking=True) @tag_Property(plot=True, private=True) def G_f(self): f0=self.f0*1.0e9 return self.offset*1e6+self.mult*0.5*Np*K2*f0*(sin(Np*pi*(freq-f0)/f0)/(Np*pi*(freq-f0)/f0))**2 @observe("f0", "mult", "offset") def update_plot(self, change): if change["type"]=="update": self.get_member("G_f").reset(self) b.plot_dict["G_f"].clt.set_ydata(self.G_f) b.draw()
class Fitter(LineFitter2): f0 = FloatRange(4.0, 6.0, d0514.qdt.f0 / 1e9).tag(tracking=True) alpha = FloatRange(0.0, 2.0, 1.0).tag(tracking=True) def _default_plotter(self): line(*self.data, plot_name=self.plot_name, plotter=pl) return pl def _default_plot_name(self): return "myplot" @tag_property(private=True) def data(self): frq = linspace(3e9, 7e9, 1000) return frq / 1e9, self.alpha * 1e9 * sqrt( d0514.qdt._get_coupling(f=frq, f0=1e9 * self.f0) / d0514.qdt.max_coupling)
class Material(Atom): #: Name name = Str() def __init__(self, name="", **kwargs): """ Constructor which accepts a material name """ super().__init__(name=name, **kwargs) transparency = FloatRange(0.0, 1.0, 0.0) shininess = FloatRange(0.0, 1.0, 0.5) refraction_index = FloatRange(1.0, value=1.0) #: Color color = ColorMember() ambient_color = ColorMember() diffuse_color = ColorMember() specular_color = ColorMember() emissive_color = ColorMember()
class Fitter(LineFitter): Ejmax=FloatRange(0.001, 100.0, qdt.Ejmax/h/1e9).tag(tracking=True) offset=FloatRange(-5.0, 5.0, 0.0).tag(tracking=True) flux_factor=FloatRange(0.1, 5.0, 0.3).tag(tracking=True) f0=FloatRange(4.0, 6.0, qdt.f0/1e9).tag(tracking=True) alpha=FloatRange(0.1, 2.0, 1.0).tag(tracking=True) def _default_plotter(self): if self.plot_name=="": self.plot_name=self.name freq=s3a4_wg.frequency[:]/1e9 freq=append(freq, freq) freq=append(freq, freq) pl1, pf=line(freq, self.data, plot_name=self.plot_name, plotter=pl) self.plot_name=pf.plot_name return pl1 @tag_Property(private=True) def data(self): return flux_par3(s3a4_wg, offset=self.offset, flux_factor=self.flux_factor, Ejmax=self.Ejmax*h*1e9, f0=self.f0*1e9, alpha=self.alpha)
class Fitter(Operative): offset=FloatRange(-1.0, 1.0, qdt.offset).tag(tracking=True) flux_factor=FloatRange(0.01, 1.0, qdt.flux_factor).tag(tracking=True) #0.299 @tag_Property(plot=True, private=True) def flux_parabola(self): flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=self.offset, flux_factor=self.flux_factor) Ej=qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) return qdt._get_fq(Ej, qdt.Ec) #return qdt.flux_parabola(voltage=self.yoko, offset=self.offset, flux_factor=self.flux_factor) yoko=Array().tag(unit="V", plot=True, label="Yoko", private=True) plotter=Typed(Plotter).tag(private=True) @observe("offset", "flux_factor") def update_plot(self, change): if change["type"]=="update": self.get_member("flux_parabola").reset(self) self.plotter.plot_dict["flux_parabola"].clt.set_ydata(self.flux_parabola) self.plotter.draw()
class Fitter(LineFitter): Ejmax = FloatRange(0.001, 100.0, qdt.Ejmax / h / 1e9).tag(tracking=True) offset = FloatRange(-5.0, 5.0, 0.0).tag(tracking=True) flux_factor = FloatRange(0.1, 5.0, 0.3).tag(tracking=True) f0 = FloatRange(4.0, 6.0, qdt.f0 / 1e9).tag(tracking=True) alpha = FloatRange(0.0, 2.0, 0.0 * qdt.couple_mult).tag(tracking=True) Ct = FloatRange(0.1, 10.0, 1.3).tag(tracking=True) def _default_plotter2(self): if self.plot_name == "": self.plot_name = self.name freq = s3a4_wg.frequency[:] / 1e9 freq = append(freq, freq) freq = append(freq, freq) pl1, pf = line(freq, self.data, plot_name=self.plot_name, plotter=pl) self.plot_name = pf.plot_name return pl1 @tag_property(private=True, plot=True) def data(self): return a.freq_axis, a.qdt._get_fluxfq0( f=a.frequency) #, plotter=pl, color="red", linewidth=1.0) return flux_par3(s3a4_wg, offset=self.offset, flux_factor=self.flux_factor, C=self.Ct * 1e-13, Ejmax=self.Ejmax * h * 1e9, f0=self.f0 * 1e9, alpha=self.alpha)
class Material_Parameters(Check): c_eta = Float(c_eta).tag( desc="The element factor", check_value=0.8, unit="for 50% metallization (Datta assuming sqrt(2) cancellation)", latex='c_\eta') material = Enum(*sorted(material_dict.keys())) def _default_material(self): return material Dvv = FloatRange(0.00001, 10 / 100.0, Dvv).tag(label="Dvv", unit=None, LiNb=2.4 / 100.0, reference="Morgan pg 9", desc="Piezoelectric coupling constant", aka="K^2/2") epsinf = FloatRange(0.0001 * 1.0e-12, 500 * 8.85e-12, epsinf).tag(label="epsilon_infty", unit="F/m", LiNb=46.0 * 8.85e-12, reference="Morgan pg 9", aka="C_S in Datta (50% metalization)", desc="Capacitance for one finger pair") v = FloatRange(1000.0, 10000.0, v).tag( label="v", unit="m/s", desc="propagation velocity of SAW (free surface)" ) # propagation velocity for YZ lithium niobate --- page 9 Morgan's Book def _observe_material(self, change): self.Dvv = material_dict[self.material]['Dvv'] self.epsinf = material_dict[self.material]['epsinf'] self.v = material_dict[self.material]['v']
class Fitter(LineFitter2): Ejmax = FloatRange(0.001, 100.0, a.qdt.Ejmax / h / 1e9).tag(tracking=True) offset = FloatRange(-5.0, 5.0, a.offset).tag(tracking=True) flux_factor = FloatRange(0.1, 5.0, a.flux_factor).tag(tracking=True) f0 = FloatRange(4.0, 6.0, a.qdt.f0 / 1e9).tag(tracking=True) alpha = FloatRange(0.0, 2.0, 1.0).tag(tracking=True) Ct = FloatRange(0.1, 10.0, a.qdt.C * 1e13).tag(tracking=True) def _default_plotter(self): line(*self.data, plot_name=self.plot_name, plotter=pl) return pl def _default_plot_name(self): return "myplot" # def _default_plotter2(self): # if self.plot_name=="": # self.plot_name=self.name # freq=s3a4_wg.frequency[:]/1e9 # freq=append(freq, freq) # freq=append(freq, freq) # pl1, pf=line(freq, self.data, plot_name=self.plot_name, plotter=pl) # self.plot_name=pf.plot_name # return pl1 @tag_property(private=True) def freq(self): freq = append(a.frequency, a.frequency) freq = append(freq, freq) return freq @tag_property(private=True) def data(self): ls_f = array([ sqrt(f * (f - self.alpha * 2 * a.qdt._get_Lamb_shift(f=f, f0=self.f0 * 1e9))) for f in a.frequency ]) #, couple_mult, K2, Np) Ec = a.qdt._get_Ec(C=self.Ct * 1e-13) Ej = a.qdt._get_Ej_get_fq(fq=ls_f, Ec=Ec) fdf0 = a.qdt._get_flux_over_flux0_get_Ej(Ej=Ej, Ejmax=self.Ejmax * h * 1e9) flux_d_flux0 = append(fdf0, -fdf0) flux_d_flux0 = append(flux_d_flux0, -fdf0 + pi) flux_d_flux0 = append(flux_d_flux0, fdf0 - pi) return self.freq / 1e9, a.qdt._get_voltage( flux_over_flux0=flux_d_flux0, offset=self.offset, flux_factor=self.flux_factor)
class Torus(Shape): """ A primitive Torus shape (a ring like shape). Attributes ---------- radius: Float Radius of the torus radius2: Float Radius of the torus profile angle: Float The angle to revolve the torus (in radians) from 0 to 2 pi. angle2: Float The angle to revolve the torus profile (in radians) from -pi/2 to pi/2. Examples -------- Torus: radius = 5 """ #: Proxy shape proxy = Typed(ProxyTorus) #: Radius of sphere radius = d_(Float(1, strict=False)).tag(view=True) #: Radius 2 radius2 = d_(Float(0, strict=False)).tag(view=True) #: Angle of U (fraction of circle) angle = d_(FloatRange(low=0.0, high=2 * pi, value=2 * pi)).tag(view=True) #: Start Angle of V (fraction of circle in normal direction) angle2 = d_(Float(0, strict=False)).tag(view=True) #: Stop Angle of V (fraction of circle in normal direction) angle3 = d_(Float(0, strict=False)).tag(view=True) @observe('radius', 'radius2', 'angle', 'angle2', 'angle3') def _update_proxy(self, change): super(Torus, self)._update_proxy(change)
class Fitter(LineFitter2): Np = Float(a.idt.Np) #.tag(tracking=True) f0 = Float(a.idt.f0 / 1e9) #.tag(tracking=True) loss = Float(-11.0) #.tag(tracking=True) L = FloatRange(400.0, 600.0, 500.0).tag(tracking=True) dloss1 = Float(0.0) dloss2 = Float(0.0) C = Float(a.idt.C) K2 = Float(a.idt.K2) dL = Float(a.idt.dL) eta = Float(a.idt.eta) def _default_plotter(self): line(*self.data, plot_name=self.plot_name, plotter=pl, color="green", linewidth=0.3, alpha=0.6) return pl def _default_plot_name(self): return "myplot" @tag_property(private=True) def data(self): return a.frequency, 20 * log10( absolute( exp(-1j * 2 * pi * a.frequency / a.idt.vf * self.L * 1e-6) * a.qdt._get_propagation_loss(f0=self.f0 * 1e9, dloss1=self.dloss1, dloss2=self.dloss2) * a.idt._get_S13(f=a.frequency, f0=self.f0 * 1e9, Np=self.Np, C=self.C, K2=self.K2, dL=self.dL, eta=self.eta))) + self.loss
class Fitter(LineFitter): Ejmax = FloatRange(0.001, 100.0, qdt.Ejmax / h / 1e9).tag(tracking=True) offset = FloatRange(-5.0, 5.0, qdt.offset).tag(tracking=True) flux_factor = FloatRange(0.1, 5.0, qdt.flux_factor).tag(tracking=True) f0 = FloatRange(4.0, 6.0, qdt.f0 / 1e9).tag(tracking=True) alpha = FloatRange(0.0, 2.0, 0.0 * qdt.couple_mult).tag(tracking=True) Ct = FloatRange(0.1, 10.0, qdt.Ct / 1e-13).tag(tracking=True) @tag_property(private=True) def frequency(self): return linspace(3.5e9, 7.5e9, 1000) # def _default_plotter(self): # if self.plot_name=="": # self.plot_name=self.name # freq=self.frequency[:]/1e9 # freq=append(freq, freq) # freq=append(freq, freq) # pl1, pf=line(*self.data, plot_name=self.plot_name, pf_too=True) # self.plot_name=pf.plot_name # return pl1 @tag_property(private=True, plot="flux_par") def data(self): freq = append(self.frequency / 1e9, self.frequency / 1e9) freq = append(freq, freq) return freq, qdt._get_Vfq0_many( f=self.frequency, f0=self.f0 * 1e9, Ct=self.Ct * 1e-13, Ejmax=self.Ejmax * h * 1e9, offset=self.offset, flux_factor=self.flux_factor)[ 1] #, plotter=pl, color="red", linewidth=1.0) return self.frequency / 1e9, qdt._get_Vfq0( f=self.frequency, f0=self.f0 * 1e9, Ct=self.Ct * 1e-13, Ejmax=self.Ejmax * h * 1e9, offset=self.offset, flux_factor=self.flux_factor ) #, plotter=pl, color="red", linewidth=1.0)
@pytest.mark.parametrize("member, set_values, values, raising_values", [ (Value(), ['a', 1, None], ['a', 1, None], []), (Bool(), [True, False], [True, False], 'r'), (Int(), [1], [1], [1.0, long(1)] if sys.version_info < (3, ) else [1.0]), (Int(strict=False), [1, 1.0, int(1)], 3 * [1], ['a']), (Long(strict=True), [long(1)], [long(1)], [1.0, 1] if sys.version_info < (3, ) else [0.1]), (Long(strict=False), [1, 1.0, int(1)], 3 * [1], ['a']), (Range(0, 2), [0, 2], [0, 2], [-1, 3]), (Range(2, 0), [0, 2], [0, 2], [-1, 3]), (Range(0), [0, 3], [0, 3], [-1]), (Range(high=2), [-1, 2], [-1, 2], [3]), (Float(), [1, int(1), 1.1], [1.0, 1.0, 1.1], ['']), (Float(strict=True), [1.1], [1.1], [1]), (FloatRange(0.0, 0.5), [0.0, 0.5], [0.0, 0.5], [-0.1, 0.6]), (FloatRange(0.5, 0.0), [0.0, 0.5], [0.0, 0.5], [-0.1, 0.6]), (FloatRange(0.0), [0.0, 0.6], [0.0, 0.6], [-0.1]), (FloatRange(high=0.5), [-0.3, 0.5], [-0.3, 0.5], [0.6]), (Bytes(), [b'a', u'a'], [b'a'] * 2, [1]), (Bytes(strict=True), [b'a'], [b'a'], [u'a']), (Str(), [b'a', u'a'], ['a'] * 2, [1]), (Str(strict=True), [b'a'] if sys.version_info < (3, ) else [u'a'], ['a'], [u'a'] if sys.version_info < (3, ) else [b'a']), (Unicode(), [b'a', u'a'], [u'a'] * 2, [1]), (Unicode(strict=True), [u'a'], [u'a'], [b'a']), (Enum(1, 2, 'a'), [1, 2, 'a'], [1, 2, 'a'], [3]), (Callable(), [int], [int], [1]), (Coerced(set), [{1}, [1], (1, )], [{1}] * 3, [1]), (Coerced(int, coercer=lambda x: int(str(x), 2)), ['101'], [5], []), (Tuple(), [(1, )], [(1, )], [[1]]),
class Fitter2(Operative): base_name = "fitter" vf = FloatRange(3000.0, 4000.0, 3488.0).tag(tracking=True) tD = FloatRange(0.0, 2000.0, 500.0).tag(tracking=True) ZS = FloatRange(10.0, 100.0, 44.38).tag(tracking=True) epsinf = FloatRange(1.0, 10.0, 2.989).tag(tracking=True) K2 = FloatRange(0.01, 0.1, 0.02458).tag(tracking=True) f0 = FloatRange(4.0, 5.0, 4.447).tag(tracking=True) Cc = FloatRange(0.00001, 100.0, 26.5).tag(tracking=True) bg_off = FloatRange(-50.0, 0.0, -24.0).tag(tracking=True) bg_slope = FloatRange(-10.0, 10.0, 0.0).tag(tracking=True) apwr = Float(1.9) avalue = FloatRange(0.0, 1.0, 0.0).tag(tracking=True) Lk = FloatRange(0.00001, 100.0, 1.0).tag(tracking=True) @tag_Property(plot=True, private=True) def R(self): w = 2 * pi * f vf = self.vf lbda = vf / f att = (self.avalue * (f / 1.0e9)**self.apwr) * 1.0e6 / vf * log(10.0) / 20.0 k = 2 * pi / lbda + 1.0j * att tL = k * self.tD * 1.0e-6 ZL = self.ZS GL = 1.0 / ZL epsinf = self.epsinf * 1.0e-10 W = 25.0e-6 Dvv = self.K2 / 2.0 f0 = self.f0 * 1.0e9 w0 = 2 * pi * f0 Np = 36 X = Np * pi * (f - f0) / f0 Ga0 = 3.11 * w0 * epsinf * W * Dvv * Np**2 Ct = sqrt(2.0) * Np * W * epsinf Cc = self.Cc * 1.0e-15 #VcdivV=self.VcdivV #L=1/(C*(wq**2.0)) Lk = self.Lk * Np * 1e-9 Ga = Ga0 * (sin(X) / X)**2.0 Ba = Ga0 * (sin(2.0 * X) - 2.0 * X) / (2.0 * X**2.0) Y = Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / (1.0j * w * Lk) Y1 = Y Y2 = Y[:] Y3 = 1.0j * w * Cc S33Full = (Y2 + 1 / ZL - ZL * (Y1 * Y3 + Y2 * Y3 + Y1 * Y2) - Y1) / (2 * Y3 + Y2 + 1.0 / ZL + ZL * (Y1 * Y3 + Y2 * Y3 + Y1 * Y2) + Y1) S11 = Ga / (Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / ZL + 1.0 / (1.0j * w * Lk)) #+1.0j*(VcdivV)*w*Cc) S33 = S33Full #(1/ZL-Y)/(1/ZL+Y) S13 = 1.0j * sqrt(2 * Ga * GL) / ( Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / ZL + 1.0 / (1.0j * w * Lk)) #+1.0j*(VcdivV)*w*Cc) S11q = Ga / (Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / ZL + 1.0 / (1.0j * w * Lk)) #+1.0j*(VcdivV)*w*Cc) S13q = 1.0j * sqrt(2 * Ga * GL) / ( Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / ZL + 1.0 / (1.0j * w * Lk)) #S21C=2.0/(2.0+1.0/(1.0j*w*Cc*ZL)) S21C = 2.0 * Y3 / (2.0 * Y3 + Y2 + Y1 + 1 / ZL + ZL * (Y1 * Y3 + Y2 * Y3 + Y1 * Y2)) crosstalk = S21C * S13q * S13 / (exp(-1.0j * tL) - S11 * exp(1.0j * tL) * S11q) return S33 + S13**2 / (exp(-2.0j * tL) / S11q - S11) + crosstalk plotter = Typed(Plotter).tag(private=True) @observe("vf", "tD", "ZS", "epsinf", "K2", "f0", "Cc", "apwr", "avalue", "bg_off", "Lk", "bg_slope") def update_plot(self, change): if change["type"] == "update": self.get_member("R").reset(self) self.plotter.plot_dict["R_theory"].clt.set_ydata( 20.0 * log10(absolute(self.R)) + self.bg_off + self.bg_slope * f * 1e-9) self.plotter.draw()
class Fitter2(Operative): base_name = "fitter" vf = FloatRange(3000.0, 4000.0, 3488.0).tag(tracking=True) tD = FloatRange(0.0, 2000.0, 500.0).tag(tracking=True) ZS = FloatRange(10.0, 100.0, 44.38).tag(tracking=True) epsinf = FloatRange(1.0, 10.0, 4.0).tag(tracking=True) K2 = FloatRange(0.01, 0.1, 0.02458).tag(tracking=True) f0 = FloatRange(4.0, 6.0, 5.25).tag(tracking=True) Cc = FloatRange(0.00001, 100.0, 26.5).tag(tracking=True) bg_off = FloatRange(-50.0, 0.0, -24.0).tag(tracking=True) bg_slope = FloatRange(-10.0, 10.0, 0.0).tag(tracking=True) apwr = Float(1.9) avalue = FloatRange(0.0, 1.0, 0.0).tag(tracking=True) Lk = FloatRange(0.00001, 100.0, 1.0).tag(tracking=True) @tag_Property(plot=True, private=True) def R(self): f = a.frequency w = 2 * pi * f #vf=self.vf #lbda=vf/f #att=(self.avalue*(f/1.0e9)**self.apwr)*1.0e6/vf*log(10.0)/20.0 #k=2*pi/lbda+1.0j*att #tL=k*self.tD*1.0e-6 #L=1/(qdt.Ct*(2*pi*c.flux_parabola)**2) #GL=1.0/ZL epsinf = self.epsinf * 1.0e-10 W = 25.0e-6 Dvv = self.K2 / 2.0 f0 = self.f0 * 1.0e9 w0 = 2 * pi * f0 Np = 9 X = Np * pi * (f - f0) / f0 Ga0 = 3.11 * w0 * epsinf * W * Dvv * Np**2 Ct = sqrt(2.0) * Np * W * epsinf #Cc=self.Cc*1.0e-15 #VcdivV=self.VcdivV #L=1/(C*(wq**2.0)) #Lk=self.Lk*Np*1e-9 Ga = Ga0 * (sin(X) / X)**2.0 Ba = Ga0 * (sin(2.0 * X) - 2.0 * X) / (2.0 * X**2.0) lamb = 1e9 * (sin(2.0 * X) - 2.0 * X) / (2.0 * X**2.0) return lamb flux_over_flux0 = (a.yoko - c.offset) * c.flux_factor R = [] R2 = [] print Ct #return Ba/w for fof0 in flux_over_flux0: Ej = qdt.Ejmax * absolute(cos(pi * fof0)) Ec = e**2 / (2.0 * Ct) E0 = sqrt(8.0 * Ej * Ec) * 0.5 - Ec / 4.0 E1 = sqrt(8.0 * Ej * Ec) * 1.5 - (Ec / 12.0) * ( 6.0 + 6.0 + 3.0) #+lamb*h fq = (E1 - E0) / h L = 1 / (qdt.Ct * (2 * pi * fq)**2) R.append( absolute(Ga / (Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / (1.0j * w * L)))** 2) # for l in L]#+1.0j*(VcdivV)*w*Cc) fqq = fq - Ec / 2.0 / h #-lamb L = 1 / (qdt.Ct * (2 * pi * fqq)**2) R2.append( absolute(Ga / (Ga + 1.0j * Ba + 1.0j * w * Ct + 1.0 / (1.0j * w * L)))** 2) # for l in L]#+1.0j*(VcdivV)*w*Cc) return R, R2
(Bool(), [True, False], [True, False], 'r'), (Int(strict=True), [1], [1], [1.0, long(1)] if sys.version_info < (3, ) else [1.0]), (Int(strict=False), [1, 1.0, long(1) ], 3 * [1], ['a'] + [] if sys.version_info >= (3, ) else [1.0e35]), (Long(strict=True), [long(1)], [long(1)], [1.0, 1] if sys.version_info < (3, ) else [0.1]), (Long(strict=False), [1, 1.0, int(1)], 3 * [1], ['a']), (Range(0, 2), [0, 2], [0, 2], [-1, 3, '']), (Range(2, 0), [0, 2], [0, 2], [-1, 3]), (Range(0), [0, 3], [0, 3], [-1]), (Range(high=2), [-1, 2], [-1, 2], [3]), (Float(), [1, int(1), 1.1], [1.0, 1.0, 1.1], ['']), (Float(strict=True), [1.1], [1.1], [1]), (FloatRange(0.0, 0.5), [0.0, 0.5], [0.0, 0.5], [-0.1, 0.6]), (FloatRange(0.5, 0.0), [0.0, 0.5], [0.0, 0.5], [-0.1, 0.6]), (FloatRange(0.0), [0.0, 0.6], [0.0, 0.6], [-0.1, '']), (FloatRange(high=0.5), [-0.3, 0.5], [-0.3, 0.5], [0.6]), (Bytes(), [b'a', u'a'], [b'a'] * 2, [1]), (Bytes(strict=True), [b'a'], [b'a'], [u'a']), (Str(), [b'a', u'a'], ['a'] * 2, [1]), (Str(strict=True), [b'a'] if sys.version_info < (3, ) else [u'a'], ['a'], [u'a'] if sys.version_info < (3, ) else [b'a']), (Unicode(), [b'a', u'a'], [u'a'] * 2, [1]), (Unicode(strict=True), [u'a'], [u'a'], [b'a']), (Enum(1, 2, 'a'), [1, 2, 'a'], [1, 2, 'a'], [3]), (Callable(), [int, None], [int, None], [1]), (Coerced(set), [{1}, [1], (1, )], [{1}] * 3, [1]), (Coerced(int, coercer=lambda x: int(str(x), 2)), ['101'], [5], []), (Coerced(
class PlotItem(Control): #: Title of data series title = d_(Unicode()) #: Name name = d_(Unicode()) #: Row in plot area row = d_(Int(0)) #: Column in plot area column = d_(Int(0)) #: Pen type to use for line line_pen = d_(Instance(PEN_ARGTYPES)) #: Pen type to use for shadow shadow_pen = d_(Instance(PEN_ARGTYPES)) #: Fill level fill_level = d_(Float(strict=False)) # ‘c’ one of: r, g, b, c, m, y, k, w # R, G, B, [A] integers 0-255 # (R, G, B, [A]) tuple of integers 0-255 # float greyscale, 0.0-1.0 # int see intColor() # (int, hues) see intColor() # “RGB” hexadecimal strings; may begin with ‘#’ # “RGBA” # “RRGGBB” # “RRGGBBAA” #: Brush fill type fill_brush = d_(Instance(BRUSH_ARGTYPES)) #: Symbol to use for points symbol = d_(Enum(None, 'o', 's', 't', 'd', '+')) #: Symbol sizes for points symbol_size = d_(Float(10, strict=False)) #: Symbol pen to use symbol_pen = d_(Instance(PEN_ARGTYPES)) #: Symbol brush symbol_brush = d_(Instance(BRUSH_ARGTYPES)) #: Show legend show_legend = d_(Bool(False)) label_left = d_(Unicode()) label_right = d_(Unicode()) label_top = d_(Unicode()) label_bottom = d_(Unicode()) # H, V grid = d_(Tuple(bool, default=(False, False))) grid_alpha = d_(FloatRange(low=0.0, high=1.0, value=0.5)) #: Display a separate axis for each nested plot multi_axis = d_(Bool(True)) axis_left_ticks = d_(Callable()) axis_bottom_ticks = d_(Callable()) #: Display the axis on log scale log_mode = d_(Tuple(bool, default=(False, False))) # x,y #: Enable antialiasing antialias = d_(Bool(False)) #: Set auto range for each axis auto_range = d_( Enum(True, False, (True, True), (True, False), (False, True), (False, False))) # x-range to use if auto_range is disabled range_x = d_(ContainerList(default=[0, 100])) #: y-range to use if auto_range is disabled range_y = d_(ContainerList(default=[0, 100])) #: Automatically downsaple auto_downsample = d_(Bool(False)) #: Clip data points to view clip_to_view = d_(Bool(False)) #: Step mode to use step_mode = d_(Bool(False)) #: Keep aspect ratio locked when resizing aspect_locked = d_(Bool(False)) @observe('line_pen', 'symbol', 'symbol_size', 'symbol_pen', 'symbol_brush', 'fill_brush', 'fill_level', 'multi_axis', 'title', 'label_left', 'label_right', 'label_top', 'label_bottom', 'grid', 'grid_alpha', 'log_mode', 'antialias', 'auto_range', 'auto_downsample', 'clip_to_view', 'step_mode', 'aspect_locked', 'axis_left_ticks', 'axis_bottom_ticks', 'show_legend', 'row', 'column') def _update_proxy(self, change): """ An observer which sends state change to the proxy. """ # The superclass handler implementation is sufficient. super(PlotItem, self)._update_proxy(change) @observe('range_x', 'range_y') def _update_range(self, change): """ Handle updates and changes """ getattr(self.proxy, 'set_%s' % change['name'])(change['value'])
class test(Atom): #Ints can have units, show_value, unit_factor and low/high limits t_int = Int().tag(unit="um", show_value=True, unit_factor=20, low=0, high=5) #Ints can be shown as spin boxes or int fields t_int_intfield = Int().tag(unit="um", show_value=True, unit_factor=20, low=0, high=5, spec="intfield") #Coerced of basic types have same behavior as basic type, e.g. this coerced int acts like the Int above t_coerced_int = Coerced(int).tag(unit="um", show_value=True, unit_factor=20, low=0, high=5, spec="intfield") #ranges are represented with sliders t_range = Range(0, 5, 1) t_floatrange = FloatRange(0.0, 5.0, 1.0) #You can include other classes t_typed = Typed(subtest, ()) t_instance = Instance(subtest, ()) #lists t_list = List(default=[1.2, 1.3, 1.4]) t_containerlist = ContainerList(default=[1.2, 1.3, 1.4]).tag(unit="um") #how to do a numpy array t_coerced_arr = Coerced(ndarray, coercer=array) #.tag(private=7) #Floats can have units, show_value, unit_factor and low/high limits t_float = Float().tag(unit="GHz", show_value=True, unit_factor=0.2, low=-1.0, high=1) #A Bool demostrating the label functionality t_bool = Bool().tag(label="MY BOOL") #Unicode Field display t_unicode = Unicode("blah") #Unicode Multiline Field disply t_unicode_multiline = Unicode("blah").tag(spec="multiline") #unmapped Enum t_enum = Enum("one", "two", "three") #mapped Enum @property def t_enum_map_mapping(self): return dict(one=1, two=2, three=3) t_enum_map = Enum("one", "two", "three") #attribute mapped enum @property def t_enum_attr_mapping(self): return dict(t_int=self.t_int, t_float=self.t_float, t_bool=self.t_bool) t_enum_attr = Enum("t_int", "t_float", "t_bool").tag(map_type="attribute") #Note: extra run features (extra args, run lockout, abort) only function if chief is defined @Callable def a(self): from time import sleep log_debug("a_called") for n in range(5): log_debug(n) if self.abort: break sleep(0.4) log_debug("a_endded") @property def chief(self): return testchief @property def busy(self): return testchief.busy @property def abort(self): return testchief.abort
class StartingCondition(Atom): initial_capital_usd = Range(low=0) sell_threshold_percent = FloatRange(0.0, 100.0, 75.0) buy_momentum_days = Range(low=1)
class AnnealerDaq(Atom): """Annealer controller through a NI-DAQ 6008. The annealer control relies on the use of three channels: - one input channel is used to read the temperature measured by a thermocouple - two output channels are used to control the heater: - one actuates a swicth. - the other actuates a current regulator. The switch is meant to be used for fast temperature ramping, while the regulator is meant to be used for slow ramps or when a stable temperature is required over extended periods of time. """ #: Id of the NI-DAQ used to control the annealer. device_id = Str('Dev1') #: Id of the channel used to control the heater switch. #: The first channel is used to read the value using single end #: measurement, the second to set it. #: The user is responsible for setting up the proper jumper. heater_switch_id = List(Str(), ['ai0', 'ao0']) #: Id of the channels used to control the heater current regulator. #: The first channel is used to read the value using single end #: measurement, the second to set it. #: The user is responsible for setting up the proper jumper. heater_reg_id = List(Str(), ['ai1', 'ao1']) #: Id of the channel used to read the temperature. This measurement is done #: using a differential channel (So in the default case ai2 is the positive #: side and ai6 is the negative one, refer to the daq documentation for #: more details). temperature_id = Str('ai2') #: State of the heater switch. Changing this value directly affects the #: hardware. heater_switch_state = Bool() #: Value in V used to represent the on state of the heater switch. heater_switch_on_value = Float(5.0) #: Value in V used to represent the on state of the heater switch. heater_switch_off_value = Float(0) #: State of the heater regulator. Changing this value directly affects the #: hardware. heater_reg_state = FloatRange(low=0.0, high=1.0) #: Maximal value that can be used by the regulator. heater_reg_max_value = FloatRange(low=0.0, high=5.0, value=5.0) #: Minimal value that can be used by the regulator. heater_reg_min_value = FloatRange(low=0.0, high=5.0) def __init__(self, config: dict) -> None: for attr in ('device_id', 'heater_switch_id', 'heater_reg_id', 'temperature_id'): if attr in config: setattr(self, attr, config[attr]) def initialize(self) -> None: if nidaqmx is None: return # Validate that the device we will use exist. devices = nidaqmx.system.System.local().devices if self.device_id not in devices.device_names: raise ValueError(f'The specified device {self.device_id} does not' f' exist. Existing devices are {list(devices)}') # Create one task per channel we need to control. for task_id, ch_id in [('heater_switch', 'heater_switch_id'), ('heater_reg', 'heater_reg_id'), ('temperature', 'temperature_id')]: if task_id == 'temperature': full_id = self.device_id + '/' + getattr(self, ch_id) task = nidaqmx.Task() self._tasks[task_id] = task mode = nidaqmx.constants.TerminalConfiguration.DIFFERENTIAL task.ai_channels.add_ai_voltage_chan(full_id, terminal_config=mode) else: tasks = (nidaqmx.Task(), nidaqmx.Task()) self._tasks[task_id] = tasks # Input channel full_id = self.device_id + '/' + getattr(self, ch_id)[0] mode = nidaqmx.constants.TerminalConfiguration.RSE tasks[0].ai_channels.add_ai_voltage_chan(full_id, terminal_config=mode) # Output channel full_id = self.device_id + '/' + getattr(self, ch_id)[1] tasks[1].ao_channels.add_ao_voltage_chan(full_id, min_val=0, max_val=5) def finalize(self) -> None: for t in self._tasks.values(): if isinstance(t, (tuple, list)): for st in t: st.close() else: t.close() def read_temperature(self) -> float: """Read the temperature measured by the DAQ. """ if not nidaqmx: return 20 if 'temperature' not in self._tasks: msg = ('The connection to the DAQ must be established prior to ' 'reading the temperature by calling `initialize`') raise RuntimeError(msg) temp_volt = self._tasks['temperature'].read() # XXX do conversion temperature = temp_volt return temperature # --- Private API --------------------------------------------------------- #: NiDAQ tasks used to control the physical DAQ _tasks = Dict(Str()) def _default_heater_switch_state(self) -> bool: """Get the value from the DAQ on first read. """ if not nidaqmx: return False if 'heater_switch' not in self._tasks: msg = ('The connection to the DAQ must be established prior to ' 'reading the heater switch state by calling `initialize`') raise RuntimeError(msg) value = self._tasks['heater_switch'][0].read() return abs(value - self.heater_switch_on_value) < 1e-1 def _post_validate_heater_switch_state(self, old: Optional[bool], new: bool) -> bool: """Try to update the DAQ when a valid value is passed. """ if not nidaqmx: return new if 'heater_switch' not in self._tasks: msg = ('The connection to the DAQ must be established prior to ' 'writing the heater switch state by calling `initialize`') raise RuntimeError(msg) if new: self._tasks['heater_switch'][1].write(self.heater_switch_on_value) else: self._tasks['heater_switch'][1].write(self.heater_switch_off_value) return new def _default_heater_reg_state(self) -> float: """Get the value from the DAQ on first read. """ if not nidaqmx: return 0.0 if 'heater_reg' not in self._tasks: msg = ('The connection to the DAQ must be established prior to ' 'reading the heater regulator stqte by calling `initialize`' ) raise RuntimeError(msg) value = self._tasks['heater_reg'][0].read() return round(((value - self.heater_reg_min_value) / (self.heater_reg_max_value - self.heater_reg_min_value)), 2) def _post_validate_heater_reg_state(self, old: Optional[float], new: float): """Try to update the DAQ when a valid value is passed. """ if not nidaqmx: return new if 'heater_reg' not in self._tasks: msg = ('The connection to the DAQ must be established prior to ' 'writing the heater regulator state by calling `initialize`' ) raise RuntimeError(msg) value = (new*(self.heater_reg_max_value - self.heater_reg_min_value) + self.heater_reg_min_value) self._tasks['heater_reg'][1].write(value) return new
class Experiment(Atom): coef = FloatRange(-1.0, 1.0, 0.0) gain = Range(0, 100, 10)
"""Test the NoOp handler.""" class A(Atom): v = Member() assert A.v.default_value_mode[0] == DefaultValue.NoOp assert A().v is None @pytest.mark.parametrize( "member, expected", [ (Value(1), 1), (Range(0), 0), (Range(high=0), 0), (Range(0, value=1), 1), (FloatRange(0.0), 0.0), (FloatRange(high=0.0), 0.0), (FloatRange(0.0, value=1.0), 1.0), (Subclass(float), float), (ForwardSubclass(lambda: float), float), ], ) def test_static_handler(member, expected): """Test a static handler.""" class StaticTest(Atom): v = member mode = (DefaultValue.MemberMethod_Object if isinstance( member, ForwardSubclass) else DefaultValue.Static) assert StaticTest.v.default_value_mode[0] == mode assert StaticTest().v == expected
class Test(Backbone): a = Range(0, 3, 1) b = FloatRange(0.0, 3.0, 1.0)