Commit 5079b18a authored by Nicolas Nunez Barreto's avatar Nicolas Nunez Barreto

estructura del repositorio + clase controlador de urukul + applet de histograma en tiempo real

parent 201427ef
import random
import numpy as np
class RedPitaya:
def __init__(self):
pass
def give_measurement(self):
return 0.5*(random.random()+1)
from artiq.experiment import *
class UrukulCh(HasEnvironment):
"""Urukul single freq class
Set the frecuencies/amplitudes of each Urukul channel
"""
def build(self, ch=0, freq=100.0, amp=1.0):
# super().build() ch, amp, freq
self.ch = ch
self.amp = amp
self.freq = freq
# sets core device drivers as attributes
self.setattr_device("core")
self.channel = self.get_device(f"urukul0_ch{self.ch}")
### This two attributes will be shown in the GUI grouped by channel
# use/don't use each channel
self.state = self.get_argument(f"state_ch{self.ch}", BooleanValue(1==0), f"canal_{self.ch}")
# each channel's frequency
self.frequency = self.get_argument(f"freq_ch{self.ch}",
NumberValue(self.freq*MHz, unit='MHz', scale=MHz, min=1*MHz, max=400*MHz),
f"canal_{self.ch}")
# each channel's amplitude
self.amplitude = self.get_argument(f"amp_ch{self.ch}",
NumberValue(self.amp, min=0., max=1.),
f"canal_{self.ch}")
# if self.ch == 0:
# self.channel = self.urukul0_ch0
# self.amplitude = self.amp_ch0
# self.frequency = self.freq_ch0
# self.state = self.state_ch0
# elif self.ch == 1:
# self.channel = self.urukul0_ch1
# self.amplitude = self.amp_ch1
# self.frequency = self.freq_ch1
# self.state = self.state_ch1
# elif self.ch == 2:
# self.channel = self.urukul0_ch2
# self.amplitude = self.amp_ch2
# self.frequency = self.freq_ch2
# self.state = self.state_ch2
# elif self.ch == 3:
# self.channel = self.urukul0_ch3
# self.amplitude = self.amp_ch3
# self.frequency = self.freq_ch3
# self.state = self.state_ch3
@kernel
def initialize_channel(self):
# self.core.reset()
# initialises CPLD the selected channel
self.channel.cpld.init()
self.channel.init()
@kernel
def set_channel(self):
self.channel.set_att(0.)
self.channel.set(self.frequency, amplitude=self.amplitude)
# turn on every selected channel
if self.state == True:
self.channel.sw.on()
else:
self.channel.sw.off()
from artiq.experiment import *
from urukul_drivers import UrukulCh
import time
import numpy as np
from rpdummy import RedPitaya
class ControlAllRF(EnvExperiment):
"""Urukul control all RF withe the driver
Set the frecuencies/amplitudes of every Urukul channel
"""
def build(self):
self.setattr_device("core")
# global attenuation
self.setattr_argument("attenuation",
NumberValue(0*dB, unit='dB', scale=dB, min=0*dB, max=31*dB),
)
RF_ch0 = UrukulCh(self, ch=0, freq=100.0, amp=1.0)
RF_ch1 = UrukulCh(self, ch=1, freq=100.0, amp=1.0)
RF_ch2 = UrukulCh(self, ch=2, freq=100.0, amp=1.0)
RF_ch3 = UrukulCh(self, ch=3, freq=50.0, amp=1.0)
self.RF_chs = [RF_ch0, RF_ch1, RF_ch2, RF_ch3]
#self.RP = RedPitaya()
#self.set_dataset("Potencias", np.full(0., 10))
#@rpc
#def get_measurement(self, i):
# val = self.RP.give_measurement()
# self.mutate_dataset("Potencias", i, val)
@kernel
def run(self):
self.core.reset()
delay(100*ms)
# initialises CPLD all the selected channels
for rf_ch in self.RF_chs:
rf_ch.initialize_channel()
delay(10*ms)
for rf_ch in self.RF_chs:
rf_ch.set_channel()
#self.get_measurement(medN)
self.core.break_realtime()
......@@ -58,7 +58,7 @@ class ContinuousCountsHistograms(EnvExperiment):
self.pmt.input()
# Pre-aloco el dataset, total ya se cuan largo va a ser.
self.set_dataset('ticks', np.full(self.nro_meds, np.nan), broadcast=True, archive=False)
# delay(100*ms) # agrego el delay necesario despues del input para no tener un underflow
delay(100*ms) # agrego el delay necesario despues del input para no tener un underflow
t0 = now_mu() # guardo el tiempo de comienzo de la medicion
try:
......
from artiq.experiment import *
from time import sleep, time
import numpy as np
from scipy.stats import poisson
from artiq.experiment import *
class Histograms(EnvExperiment):
"""Histograms demo"""
def build(self):
self.setattr_argument("nbins", NumberValue(100, ndecimals=0, step=10))
self.setattr_argument("npoints", NumberValue(20, ndecimals=0, step=5))
self.setattr_argument("histo_delay", NumberValue(0.6, ndecimals=2, step=0.01))
self.setattr_device("ccb")
def run(self):
# Custom histogram plot creator (needs a reasonable --update-delay)
self.ccb.issue("create_applet", "ticks_histogram",
"${artiq_applet}plot_hist "
"histo --x hd_bins --title tit "
f"--update-delay {self.histo_delay}",
group="ExampleHistogram")
bin_boundaries = np.linspace(-10, 30, self.nbins + 1)
self.set_dataset("hd_bins", bin_boundaries,
broadcast=True, archive=False)
self.set_dataset("histo", np.empty(self.nbins), broadcast=True, archive=False)
"""
xs = np.empty(self.npoints)
xs.fill(np.nan)
self.set_dataset("hd_xs", xs,
broadcast=True, archive=False)
self.set_dataset("hd_counts", np.empty((self.npoints, self.nbins)),
broadcast=True, archive=False)
"""
for i in range(self.npoints):
tit = "hola"
t1 = time()
histogram, _ = np.histogram(np.random.normal(i, size=1000),
bin_boundaries)
for j in range(self.nbins):
self.mutate_dataset("histo", j, histogram[j])
#self.mutate_dataset("hd_counts", i, histogram)
#self.mutate_dataset("hd_xs", i, i % 8)
t2 = time()
print(t2-t1)
sleep(0.5)
sleep(0.3)
from time import sleep, time
from scipy.stats import poisson
import numpy as np
from artiq.experiment import *
class MockPMT(): #{{{
def __init__(self, mean=20):
self.mean = mean
def count(self):
return poisson.rvs(self.mean)
def change_mean(self, new_mean):
self.mean = new_mean
# }}}
class Histograms(EnvExperiment):
"""Histograms mockpmt simulation"""
def build(self):
self.setattr_argument("npoints", NumberValue(100, ndecimals=0, step=5))
self.setattr_argument("chunks", NumberValue(5, ndecimals=0, step=1))
self.setattr_argument("bin_init", NumberValue(-10, ndecimals=0, step=1), "Binning parameters")
self.setattr_argument("bin_end", NumberValue(30, ndecimals=0, step=1), "Binning parameters")
self.setattr_argument("bin_step", NumberValue(1, ndecimals=0, step=1), "Binning parameters")
self.setattr_argument("nbins", NumberValue(100, ndecimals=0, step=10))
self.setattr_argument("histo_delay", NumberValue(0.6, ndecimals=2, step=0.01))
self.setattr_device("ccb")
def run(self):
self.pmt = MockPMT()
# Custom histogram plot creator (needs a reasonable --update-delay)
self.ccb.issue("create_applet", "mockpmt_histogram",
"${artiq_applet}plot_hist "
"histo --x hd_bins --title mockpmt "
f"--update-delay {self.histo_delay}",
group="ExampleHistogram")
bin_boundaries = np.arange(self.bin_init, self.bin_end, self.bin_step)
self.set_dataset("hd_bins", bin_boundaries,
broadcast=True, archive=False)
self.set_dataset("histo", np.zeros(len(bin_boundaries)-1, dtype=int), broadcast=True, archive=False)
self.set_dataset("medidas", np.empty(self.npoints*self.chunks), broadcast=True, archive=False)
self.set_dataset("partial_chunk", np.empty(self.chunks), broadcast=True, archive=False)
for i in range(self.npoints):
for j in range(self.chunks):
self.mutate_dataset("partial_chunk", j, self.pmt.count())
print(1)
histogram_partial, _ = np.histogram(self.partial_chunk,
bin_boundaries)
print(2)
for k in range(len(histo)):
self.mutate_dataset("histo", k, self.histo[k]+histogram_partial[k])
print(3)
sleep(0.5)
sleep(0.3)
from artiq.experiment import *
class UrukulChannel(HasEnviroment):
def build(self, chN):
super().build()
print(chN)
# Todos los setattr apropiados
@kernel
def init_kernel(self):
# cosas como el init, seteo de frecuencia inicial etc
class TesteoSubmodulos(EnvExperiment):
def build(self):
# Hago las cosas que queira aca
self.controler_ch0 = UrukulChannel(0)
@kernel
def run(self):
#cosas
self.controler_ch0.init_kernel()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment