Skip to content

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielguerrer authored Jul 3, 2024
1 parent 63a1f18 commit 81f9888
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include CHANGELOG.md
include src/rng_rava/tk/rava.png
include examples/*.py
include examples/*.py
2 changes: 1 addition & 1 deletion examples/acq_bytes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
This example illustrates the generation of random bytes to binary files using
This example illustrates the generation of random bytes to binary files using
the RAVA_ACQUISITION class.
This example code is in the public domain.
Expand Down
4 changes: 2 additions & 2 deletions examples/acq_floats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
This example illustrates the generation of random floats to a binary file
This example illustrates the generation of random floats to a binary file
(numpy npy) using the RAVA_ACQUISITION class.
This example code is in the public domain.
Expand Down Expand Up @@ -35,7 +35,7 @@
rng_acq.cbkreg_progress(lambda progress: print('{:.0f}%'.format(progress)))

# Acquisition
outputs, progress, time_str = rng_acq.get_numbers(rng, N_NUMS, N_CHUNK, NUM_TYPE, NUM_MIN, NUM_MAX,
outputs, progress, time_str = rng_acq.get_numbers(rng, N_NUMS, N_CHUNK, NUM_TYPE, NUM_MIN, NUM_MAX,
OUT_FILE, OUT_PATH, OUT_BINARY, threaded=THREADED)

# Close RAVA device
Expand Down
4 changes: 2 additions & 2 deletions examples/acq_ints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
This example illustrates the generation of random integers to a text file
This example illustrates the generation of random integers to a text file
using the RAVA_ACQUISITION class.
This example code is in the public domain.
Expand Down Expand Up @@ -36,7 +36,7 @@
rng_acq.cbkreg_progress(lambda progress: print('{:.0f}%'.format(progress)))

# Acquisition
outputs, progress, time_str = rng_acq.get_numbers(rng, N_NUMS, N_CHUNK, NUM_TYPE, NUM_MIN, NUM_MAX,
outputs, progress, time_str = rng_acq.get_numbers(rng, N_NUMS, N_CHUNK, NUM_TYPE, NUM_MIN, NUM_MAX,
OUT_FILE, OUT_PATH, OUT_BINARY, OUT_SEP, THREADED)

# Close RAVA device
Expand Down
4 changes: 2 additions & 2 deletions examples/acq_pcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
This example illustrates the generation of pulse counts to memory array using
This example illustrates the generation of pulse counts to memory array using
the RAVA_ACQUISITION class. The generation runs in threaded mode.
This example code is in the public domain.
Expand Down Expand Up @@ -37,7 +37,7 @@ def finished(future):
# Print first 100 entries from each array
print(outputs[0][:100])
print(outputs[1][:100])

# Close RAVA device
rng.close()

Expand Down
8 changes: 4 additions & 4 deletions examples/rng_doubles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def get_rng_doubles(n_doubles):
return
rnd_bytes_a, rnd_bytes_b = bytes_res

# XOR them
# XOR them
rnd_bytes = np.bitwise_xor(rnd_bytes_a, rnd_bytes_b).tobytes()
# Convert bytes to ints

# Convert bytes to ints
rnd_ints = np.frombuffer(rnd_bytes, dtype=np.uint64)

# IEEE754 bit pattern for single precision floating point value in the
# range of 1.0 - 2.0. Uses the first 52 bits and fixes the float
# exponent to 1023
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rng_rava"
version = "1.2.0"
version = "1.2.1"
authors = [
{ name="Gabriel Guerrer", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion src/rng_rava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Distributed under the MIT license - See LICENSE for details
"""

__version__ = '1.2.0'
__version__ = '1.2.1'

from .rava_defs import *
from .rava_rng import *
Expand Down
20 changes: 10 additions & 10 deletions src/rng_rava/acq/rava_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
Generation can occur in either threaded or blocking mode, and the output
can be presented as a memory array or a disk file.
For the get_pulse_counts() and get_bytes() functions, when out_file=True, they
generate binary files. In contrast, the get_numbers() function provides the
option to produce a text file by setting the parameter out_file_binary=False.
In the text output, entries are separated by the out_separator character.
When get_numbers() has the parameter out_file_binary=True, the files are
For the get_pulse_counts() and get_bytes() functions, when out_file=True, they
generate binary files. In contrast, the get_numbers() function provides the
option to produce a text file by setting the parameter out_file_binary=False.
In the text output, entries are separated by the out_separator character.
When get_numbers() has the parameter out_file_binary=True, the files are
saved using the numpy npy file format.
The get_numbers() function generates one file or array, which alternates entries
from both RNG cores. The get_pulse_counts() and get_bytes() functions accept a
The get_numbers() function generates one file or array, which alternates entries
from both RNG cores. The get_pulse_counts() and get_bytes() functions accept a
rng_out parameter, which can be:
* 'A': 1 output file, RNG core A only
* 'B': 1 output file, RNG core B only
* 'AB': 2 output files, RNG cores A and B independent data
For get_bytes(), the parameter rng_out also accepts:
* 'AB_XOR': 1 output file, obtained by XORing RNG cores A and B output
* 'AB_ALT': 1 output file, with alternating bytes from RNG cores A and B.
* 'AB_ALT': 1 output file, with alternating bytes from RNG cores A and B.
Requires half of the time to produce n_bytes
A progress callback is established by registering a function through
cbkreg_progress(). This function is invoked every time a data chunk of size
A progress callback is established by registering a function through
cbkreg_progress(). This function is invoked every time a data chunk of size
n_chunk is generated, providing information about the progress percentage.
"""

Expand Down
4 changes: 2 additions & 2 deletions src/rng_rava/tk/acq/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
To execute it, enter the following command: python3 -m rng_rava.tk.acq
"""

import rng_rava as rava
import rng_rava as rava

TITLE = 'RAVA Acquisition'

rava_subapp_control_panel = rava.tk.ctrlp.rava_subapp_control_panel
rava_subapp_control_panel['show_button']= False
SUBAPPS = [rava_subapp_control_panel,
SUBAPPS = [rava_subapp_control_panel,
rava.tk.acq.rava_subapp_acquisition]


Expand Down
72 changes: 36 additions & 36 deletions src/rng_rava/tk/acq/rava_subapp_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""

"""
The Acquisition sub-app features a GUI interface for utilizing the
RAVA_ACQUISITION class, which allows the generation of files comprising pulse
The Acquisition sub-app features a GUI interface for utilizing the
RAVA_ACQUISITION class, which allows the generation of files comprising pulse
counts, bytes, or numbers extracted from a RAVA device.
"""

Expand Down Expand Up @@ -37,11 +37,11 @@
class RAVA_SUBAPP_ACQUISITION(RAVA_SUBAPP):

cfg_default_str = '''
[ACQUISITION]
[ACQUISITION]
chunk_bytes = 10000
chunk_numbers = 5000
delete_incomplete = True
path_out =
path_out =
'''

def __init__(self, parent):
Expand All @@ -55,10 +55,10 @@ def __init__(self, parent):

# Windows
self.win_progress = WIN_PROGRESS(self)
self.win_progress.hide()
self.win_progress.hide()

# Widgets
self.nb = ttk.Notebook(self, padding=PAD)
self.nb = ttk.Notebook(self, padding=PAD)
self.nb.grid(row=0, column=0, sticky='nsew')

self.frm_pcs = ttk.Frame(self, name='pulsecounts')
Expand All @@ -76,18 +76,18 @@ def __init__(self, parent):
self.nb.add(self.frm_pcs, text=' Pulse Counts ')
self.nb.add(self.frm_bytes, text=' Bytes ')
self.nb.add(self.nfrm_nums, text=' Numbers ')

## Start
# Config

# Config
delete_incomplete = self.cfg.read('ACQUISITION', 'delete_incomplete', bool)
out_path = self.cfg.read('ACQUISITION', 'path_out')
self.var_acq_path.set(out_path)

# RAVA_ACQUISITION
self.rng_acq = RAVA_ACQUISITION(delete_incomplete=delete_incomplete)
self.rng_acq.cbkreg_progress(self.win_progress.prog_update)
self.rng_acq.cbkreg_progress(self.win_progress.prog_update)


def pcs_widgets(self):
self.frm_pcs.columnconfigure([0], weight=1)
Expand Down Expand Up @@ -144,11 +144,11 @@ def pcs_widgets(self):
# Preset
self.lb_pcs_preset = ttk.Label(self.frm_pcs_pars, text='Preset')
self.lb_pcs_preset.grid(row=2, column=0, sticky='w')

self.cbb_pcs_preset = ttk.Combobox(self.frm_pcs_pars, width=8, )
self.cbb_pcs_preset.grid(row=2, column=1, sticky='w')
self.cbb_pcs_preset.state(['readonly'])
self.cbb_pcs_preset['values'] = ['Report', 'Detailed']
self.cbb_pcs_preset['values'] = ['Report', 'Detailed']
self.cbb_pcs_preset.bind('<<ComboboxSelected>>', self.pcs_preset_sel)
self.cbb_pcs_preset.set('Report')

Expand Down Expand Up @@ -215,11 +215,11 @@ def bytes_widgets(self):
# Preset
self.lb_bytes_preset = ttk.Label(self.frm_bytes_pars, text='Preset')
self.lb_bytes_preset.grid(row=2, column=0, sticky='w')

self.cbb_bytes_preset = ttk.Combobox(self.frm_bytes_pars, width=8, )
self.cbb_bytes_preset.grid(row=2, column=1, sticky='w')
self.cbb_bytes_preset.state(['readonly'])
self.cbb_bytes_preset['values'] = ['Report']
self.cbb_bytes_preset['values'] = ['Report']
self.cbb_bytes_preset.bind('<<ComboboxSelected>>', self.bytes_preset_sel)
self.cbb_bytes_preset.set('Report')

Expand Down Expand Up @@ -252,7 +252,7 @@ def nums_widgets(self):
# Number type
self.lb_nums_type = ttk.Label(self.nfrm_nums_pars, text='Number (type, N)')
self.lb_nums_type.grid(row=0, column=0, sticky='w')

self.cbb_nums_type = ttk.Combobox(self.nfrm_nums_pars, width=9)
self.cbb_nums_type.grid(row=0, column=1, sticky='w')
self.cbb_nums_type.state(['readonly'])
Expand All @@ -268,7 +268,7 @@ def nums_widgets(self):
self.cbb_nums_n_mult.grid(row=0, column=3, sticky='w')
self.cbb_nums_n_mult.state(['readonly'])
self.cbb_nums_n_mult['values'] = ['', 'K', 'M', 'G', 'T']
self.cbb_nums_n_mult.set('M')
self.cbb_nums_n_mult.set('M')

# Number range
self.lb_nums_range = ttk.Label(self.nfrm_nums_pars, text='Range (min, max)')
Expand Down Expand Up @@ -320,31 +320,31 @@ def acquisition_finished(self, future):
# Show result info
if progress == 100:
title_msg = 'Success'
else:
else:
title_msg = 'Canceled'

time_msg = 'Time = ' + time_str

if len(outputs):
detail_msg = '\nGenerated files\n{}'.format(outputs)
else:
else:
detail_msg = '\nIncomplete files deleted'

tkm.showinfo(parent=self.win_progress, title=title_msg, message=time_msg, detail=detail_msg)
tkm.showinfo(parent=self.win_progress, title=title_msg, message=time_msg, detail=detail_msg)

# Close win_progress
self.win_progress.hide()


def acq_path_search(self):
out_path0 = self.var_acq_path.get()
out_path0 = self.var_acq_path.get()
out_path0 = out_path0 if out_path0 and os.path.exists(out_path0) else '/'
out_path = tk.filedialog.askdirectory(parent=self, initialdir=out_path0, mustexist=True)
if out_path:
self.var_acq_path.set(out_path)
self.cfg.write('ACQUISITION', 'path_out', out_path)


def pcs_preset_sel(self, tk_event=None):
if self.cbb_pcs_preset.get() == 'Report':
self.var_pcs_si_min.set(10)
Expand All @@ -360,17 +360,17 @@ def pcs_preset_sel(self, tk_event=None):
self.var_pcs_n.set(10)
self.cbb_pcs_n_mult.set('M')


def pcs_generate(self):
# Read vars
out_path = self.var_acq_path.get()
if not os.access(out_path, os.W_OK):
tkm.showerror(parent=self, message='Error', detail='Cannot write on the chosen directory')
return

si_min = self.var_pcs_si_min.get()
si_max = self.var_pcs_si_max.get()
si_step = self.var_pcs_si_step.get()
si_step = self.var_pcs_si_step.get()
si_range = np.arange(si_min, si_max + 1, si_step)
n_si_range = len(si_range)
if n_si_range == 0:
Expand Down Expand Up @@ -401,7 +401,7 @@ def pcs_generate(self):
# Show progress window
with self.win_progress:

# Loop PCs acquisition
# Loop PCs acquisition
canceled = False
for i, si in enumerate(si_range):

Expand All @@ -412,7 +412,7 @@ def pcs_generate(self):
self.rng.snd_rng_setup(si)

# Collect PCs
outputs, _, _ = self.rng_acq.get_pulse_counts(rng=self.rng, n_pcs=n_pcs, n_chunk=n_chunk, rng_out='AB',
outputs, _, _ = self.rng_acq.get_pulse_counts(rng=self.rng, n_pcs=n_pcs, n_chunk=n_chunk, rng_out='AB',
out_file=False, out_path='', threaded=False)
if len(outputs):
pcs_a[i], pcs_b[i] = outputs
Expand All @@ -438,7 +438,7 @@ def pcs_generate(self):
out_name = '{}_PCS_{}_SI_{}_{}_{}__'.format(sn, n_pcs_str, si_min, si_max, si_step)
n_out_name = len(glob(os.path.join(out_path, out_name + '*.npz')))
output_file = os.path.join(out_path, out_name + '{}.npz'.format(n_out_name + 1))

np.savez_compressed(output_file, pwm_setup=pwm_setup, rng_setup=rng_setup, si_range=si_range, pcs_a=pcs_a, pcs_b=pcs_b)

# Info screen
Expand Down Expand Up @@ -476,9 +476,9 @@ def bytes_generate(self):
self.lg.info('{}: Generating {} Bytes; postproc={}, rng_out={}'.format(self.name, n_bytes, postproc, rng_out))

# Start byte acquisition
self.win_progress.show()
self.win_progress.show()

result_future = self.rng_acq.get_bytes(rng=self.rng, n_bytes=n_bytes, n_chunk=n_chunk, postproc=postproc,
result_future = self.rng_acq.get_bytes(rng=self.rng, n_bytes=n_bytes, n_chunk=n_chunk, postproc=postproc,
rng_out=rng_out, out_file=True, out_path=out_path, threaded=True)
result_future.add_done_callback(self.acquisition_finished)

Expand All @@ -505,7 +505,7 @@ def nums_generate(self):
if not os.access(out_path, os.W_OK):
tkm.showerror(parent=self, title='Error', message='Cannot write on the chosen directory')
return

num_type_str = self.cbb_nums_type.get()
num_type = int if num_type_str == 'INT' else float
n_nums = int(get_ammount_prefix_number(n=self.var_nums_n.get(), prefix=self.cbb_nums_n_mult.get()))
Expand All @@ -524,11 +524,11 @@ def nums_generate(self):
.format(self.name, n_nums, num_type_str, num_min, num_max))

# Start number acquisition
self.win_progress.show()
self.win_progress.show()

result_future = self.rng_acq.get_numbers(rng=self.rng, n_nums=n_nums, n_chunk=n_chunk, num_type=num_type,
num_min=num_min, num_max=num_max, out_file=True, out_path=out_path,
out_file_binary=out_binary, out_file_separator=out_separator,
result_future = self.rng_acq.get_numbers(rng=self.rng, n_nums=n_nums, n_chunk=n_chunk, num_type=num_type,
num_min=num_min, num_max=num_max, out_file=True, out_path=out_path,
out_file_binary=out_binary, out_file_separator=out_separator,
threaded=True)
result_future.add_done_callback(self.acquisition_finished)

Expand Down
Loading

0 comments on commit 81f9888

Please sign in to comment.