Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming of slice variables to slab - Fixes issue #21 #22

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Additional contributions by (new contributors, add yourself here):
* Alexander Merino
* Tristan Long
* Kayla Barton
* Christopher McLean

# Copyright

Expand Down
24 changes: 12 additions & 12 deletions devtools/data_creation/correlation_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def generate_data(self):

def configure(self, tile_x, tile_y, model_positions, convergence_step=None):
self.model_positions = model_positions
self.slices = []
self.slabs = []
batch_start_index = 0
while batch_start_index < self.num_traces:
entry_count = min(self.batch_size, self.num_traces - batch_start_index)
self.slices.append(slice(batch_start_index, batch_start_index+entry_count))
self.slabs.append(slice(batch_start_index, batch_start_index+entry_count))
batch_start_index += entry_count

return 1
Expand All @@ -53,25 +53,25 @@ def get_traces(self):
def get_key(self):
return self.key

def get_byte_batch(self, slice, model_pos):
def get_byte_batch(self, slab, model_pos):

return [self.plaintext[slice, [model_pos]], self.key[[model_pos]], self.traces[slice,:]]
return [self.plaintext[slab, [model_pos]], self.key[[model_pos]], self.traces[slab,:]]

def get_batches_by_byte(self, tile_x, tile_y, model_pos):
for slice in self.slices:
yield self.get_byte_batch(slice, model_pos)
for slab in self.slabs:
yield self.get_byte_batch(slab, model_pos)

def get_batch(self, slice):
def get_batch(self, slab):

return [self.plaintext[slice,self.model_positions], self.key[self.model_positions], self.traces[slice,:]]
return [self.plaintext[slab,self.model_positions], self.key[self.model_positions], self.traces[slab,:]]

def get_batches_all(self, tile_x, tile_y):
for slice in self.slices:
yield self.get_batch(slice)
for slab in self.slabs:
yield self.get_batch(slab)

def get_batch_index(self, index):

if index >= len(self.slices):
if index >= len(self.slabs):
return []

return [self.plaintext[self.slices[index], self.model_positions], self.key[self.model_positions], self.traces[self.slices[index], :]]
return [self.plaintext[self.slabs[index], self.model_positions], self.key[self.model_positions], self.traces[self.slabs[index], :]]
1 change: 1 addition & 0 deletions license_check.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ authorized_licenses:
Historical Permission Notice and Disclaimer (HPND)
Other/Proprietary
The Unlicense (Unlicense)
CMU License (MIT-CMU)

unauthorized_licenses:
gpl v3
Expand Down
34 changes: 17 additions & 17 deletions src/scarr/container/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Container:
- byte_positions: The byte positions to be processed by the algorithm has a default value of [0]
- tile_positions: The tile positions that are to have the byte positions processed default value of [(0,0)]
"""
def __init__(self, options: ContainerOptions, Async = True, model_positions = [0], tile_positions = [(0,0)], filters = [], points=[], trace_index=[], slice=[], stride=1) -> None:
def __init__(self, options: ContainerOptions, Async = True, model_positions = [0], tile_positions = [(0,0)], filters = [], points=[], trace_index=[], slab=[], stride=1) -> None:
self.engine = options.engine
self.data = options.handler
self.data2 = options.handler2 # second trace (only t-test)
Expand All @@ -48,28 +48,28 @@ def __init__(self, options: ContainerOptions, Async = True, model_positions = [0
self.min_traces_length = 0

if len(points) > 0:
self.slice_index = points
self.time_slice = []
self.slab_points = points
self.slab_range = []
self.stride = 1
self.sample_length = len(points)
elif len(slice) == 2 and stride > 1:
self.slice_index = []
self.time_slice = slice
elif len(slab) == 2 and stride > 1:
self.slab_points = []
self.slab_range = slab
self.stride = stride
self.sample_length = math.ceil((self.time_slice[1] - self.time_slice[0]) / stride)
elif len(slice) == 2:
self.slice_index = []
self.time_slice = slice
self.sample_length = math.ceil((self.slab_range[1] - self.slab_range[0]) / stride)
elif len(slab) == 2:
self.slab_points = []
self.slab_range = slab
self.stride = 1
self.sample_length = int(self.time_slice[1] - self.time_slice[0])
self.sample_length = int(self.slab_range[1] - self.slab_range[0])
elif stride > 1:
self.slice_index = []
self.time_slice = []
self.slab_points = []
self.slab_range = []
self.stride = stride
self.sample_length = math.ceil(self.data.sample_length / self.stride)
else:
self.slice_index = []
self.time_slice = []
self.slab_points = []
self.slab_range = []
self.stride = 1
self.sample_length = self.data.sample_length

Expand All @@ -86,13 +86,13 @@ def configure(self, tile_x, tile_y, model_positions, convergence_step = None):
for filter in self.filters:
filter.configure(tile_x, tile_y)
# int() casting needed for random typing linux bug
return int(self.data.configure(tile_x, tile_y, model_positions, self.slice_index, self.trace_index, self.time_slice, self.stride, convergence_step))
return int(self.data.configure(tile_x, tile_y, model_positions, self.slab_points, self.trace_index, self.slab_range, self.stride, convergence_step))

def configure2(self, tile_x, tile_y, model_positions, convergence_step = None):
for filter in self.filters:
filter.configure(tile_x, tile_y)
# int() casting needed for random typing linux bug
return int(self.data2.configure(tile_x, tile_y, model_positions, self.slice_index, self.trace_index, self.time_slice, self.stride, convergence_step))
return int(self.data2.configure(tile_x, tile_y, model_positions, self.slab_points, self.trace_index, self.slab_range, self.stride, convergence_step))

def get_batches(self, tile_x, tile_y):
for batch in self.data.get_batch_generator():
Expand Down
60 changes: 30 additions & 30 deletions src/scarr/file_handling/trace_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self,
self.model_positions = None
# How many rows are in the current observed directory of the file
self.data_length = None
self.slices = None
self.slabs = None
# Default directory of the zarr file
self.current_tile = '0/0' # Default tile
# Zarr group
Expand All @@ -36,28 +36,28 @@ def __init__(self,
self.traces_length = len(self.data['0/0/traces'])

# Change the directory to the passed in tile
def configure(self, tile_x, tile_y, model_positions, slice_index=[], trace_index=[], time_slice=[], stride=1, convergence_step = None):
def configure(self, tile_x, tile_y, model_positions, slab_points=[], trace_index=[], slab_range=[], stride=1, convergence_step = None):
try:
self.model_positions = model_positions
self.current_tile = f'{tile_x}/{tile_y}'
self.data_length = len(self.data[f'{self.current_tile}{"/traces"}'])

if len(slice_index) > 0:
self.sample_slice = slice_index
elif len(time_slice) == 2 and stride > 1:
self.sample_slice = slice(time_slice[0], time_slice[1], stride)
elif len(time_slice) == 2:
self.sample_slice = slice(time_slice[0], time_slice[1])
if len(slab_points) > 0:
self.sample_slab = slab_points
elif len(slab_range) == 2 and stride > 1:
self.sample_slab = slice(slab_range[0], slab_range[1], stride)
elif len(slab_range) == 2:
self.sample_slab = slice(slab_range[0], slab_range[1])
elif stride > 1:
self.sample_slice= slice(0, self.sample_length, stride)
self.sample_slab= slice(0, self.sample_length, stride)
else:
self.sample_slice = slice(None)
self.sample_slab = slice(None)

if len(trace_index) > 0:
self.data_length = len(trace_index)
self.slices = self.create_batches_index(trace_index)
self.slabs = self.create_batches_index(trace_index)
else:
self.slices = self.create_batches()
self.slabs = self.create_batches()

if convergence_step is None:
return 1
Expand All @@ -68,7 +68,7 @@ def configure(self, tile_x, tile_y, model_positions, slice_index=[], trace_index
print("Error configuring tile")

# Grab a batch and pass it back to the algorithm's run function
def grab(self, slice):
def grab(self, slab):

# Declare and select data for the batch
full_data = [None for i in range(4)]
Expand All @@ -82,64 +82,64 @@ def grab(self, slice):
index = 2
case _:
continue
full_data[index] = self.select_single_column(column, slice)
full_data[3] = self.select_traces(slice)
full_data[index] = self.select_single_column(column, slab)
full_data[3] = self.select_traces(slab)
# Pass batch to the algorithm's run function
return full_data

# Fetch data of a non-samples zarr array
def select_single_column(self, col_name, slice):
def select_single_column(self, col_name, slab):
# Grab zarr array
col_data = self.data[f'{self.current_tile}/{col_name}']
# Grab the actual data
data = col_data.get_orthogonal_selection((slice, self.model_positions))
data = col_data.get_orthogonal_selection((slab, self.model_positions))
# Pass to grab
return data

# Specific function for grabbing sample data
def select_traces(self, slice):
def select_traces(self, slab):
# Grab zarr array of samples
traces = self.data[f'{self.current_tile}/traces']
# Grab the actual data
data = traces.get_orthogonal_selection((slice, self.sample_slice))
data = traces.get_orthogonal_selection((slab, self.sample_slab))
# Pass to grab
return data

def get_batch_generator(self):
for batch_slice in self.slices:
yield self.grab(batch_slice)
for batch_slab in self.slabs:
yield self.grab(batch_slab)

def get_batch_index(self, index):
if index >= len(self.slices):
if index >= len(self.slabs):
return []

return self.grab(self.slices[index])
return self.grab(self.slabs[index])

def create_batches(self):
slices = []
slabs = []
batch_start_index = self.start

while batch_start_index < self.data_length:
entry_count = min(self.batch_size, self.data_length - batch_start_index)
slices.append(slice(batch_start_index, batch_start_index+entry_count))
slabs.append(slice(batch_start_index, batch_start_index+entry_count))
batch_start_index += entry_count

return slices
return slabs

def create_batches_index(self, index):
slices = []
slabs = []
batch_start_index = 0

while batch_start_index < len(index):
entry_count = min(self.batch_size, len(index) - batch_start_index)
slices.append(index[batch_start_index:batch_start_index+entry_count])
slabs.append(index[batch_start_index:batch_start_index+entry_count])
batch_start_index += entry_count

return slices
return slabs

def fetch(self, column, tile_x=0, tile_y=0, row_index = 0, col_index=None):
if col_index is None:
col_index = slice(None)
column_data = self.data[f'{tile_x}/{tile_y}/{column}']

return column_data.get_orthogonal_selection((row_index, col_index))
return column_data.get_orthogonal_selection((row_index, col_index))