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

Implement slicing for LB #4178

Closed
wants to merge 0 commits into from
Closed

Conversation

KaiserMartin
Copy link
Contributor

Fixes #4143

Description of changes:

  • Modified getitem to detect slices in input keys
  • Introduced LBSlice class that calculates node indices from slice input and calls single node getter from LBFLuidRoutines class for every node in the slice.

The output is a multidimensional array containing the requested quantity and is of dimension len(slice_x)*len(slice_y)*len(slice_z)*len(quantity), where len(quantity) is the dimensions of the quantity, for example 3 in case of velocity. The output array is arranged in the way numpy cycles through slices. Therefore, when setting attributes one has to set the dimensions of the input array exactly the same way numpy cycles through the sliced nodes.
An error is issued if the dimensions of the slices and the input does not match.

src/python/espressomd/lb.pyx Outdated Show resolved Hide resolved
src/python/espressomd/lb.pyx Outdated Show resolved Hide resolved
Copy link
Contributor Author

@KaiserMartin KaiserMartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Removing unnecessary c variables from population and squeezing output from property boundary so it has the right dimensions

Comment on lines 557 to 560
def __init__(self, key):
shape = lb_lbfluid_get_shape()
self.x_indices, self.y_indices, self.z_indices = self.get_indices(
key, shape[0], shape[1], shape[2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, key):
shape = lb_lbfluid_get_shape()
self.x_indices, self.y_indices, self.z_indices = self.get_indices(
key, shape[0], shape[1], shape[2])
def __init__(self, key, shape):
self.shape = shape
self.x_indices, self.y_indices, self.z_indices = self.get_indices(
key, shape[0], shape[1], shape[2])

@@ -542,3 +548,137 @@ cdef class LBFluidRoutines:

def __set__(self, value):
raise NotImplementedError

cdef class LBSlice:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cdef class LBSlice:
class LBSlice:

Comment on lines 553 to 555
cdef np.ndarray x_indices
cdef np.ndarray y_indices
cdef np.ndarray z_indices
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cdef np.ndarray x_indices
cdef np.ndarray y_indices
cdef np.ndarray z_indices


property density:
def __get__(self):
prop_name = "density"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_name = "density"

self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3)

def __set__(self, value):
prop_name = "density"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_name = "density"


property pressure_tensor_neq:
def __get__(self):
prop_name = "pressure_tensor_neq"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_name = "pressure_tensor_neq"


property population:
def __get__(self):
prop_name = "population"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_name = "population"

self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res)

def __set__(self, value):
prop_name = "population"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_name = "population"

property boundary:
def __get__(self):
shape_res = (1,)
prop_name = "boundary"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_name = "boundary"

Comment on lines 589 to 604
property density:
def __get__(self):
prop_name = "density"
shape_res = (1,)
return np.squeeze(self.get_values(
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3)

def __set__(self, value):
prop_name = "density"
self.set_values(
self.x_indices,
self.y_indices,
self.z_indices,
prop_name,
value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
property density:
def __get__(self):
prop_name = "density"
shape_res = (1,)
return np.squeeze(self.get_values(
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3)
def __set__(self, value):
prop_name = "density"
self.set_values(
self.x_indices,
self.y_indices,
self.z_indices,
prop_name,
value)
@property
def density(self):
prop_name = "density"
shape_res = (1,)
return np.squeeze(self.get_values(
self.x_indices, self.y_indices, self.z_indices, prop_name, shape_res), axis=3)
@density.setter
def density(self, value):
self.set_values(
self.x_indices,
self.y_indices,
self.z_indices,
prop_name,
value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the modern python syntax for properties

@jngrad
Copy link
Member

jngrad commented Mar 31, 2021

@KaiserMartin Here is the result of applying Kai's review: jngrad/espresso@fix-4143 (diff view)

Copy link
Member

@jngrad jngrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR ready for merge from my side.

@jngrad jngrad requested a review from KaiSzuttor March 31, 2021 15:55
@jngrad jngrad added this to the Espresso 4.2 milestone Mar 31, 2021
RudolfWeeber
RudolfWeeber previously approved these changes Mar 31, 2021
@jngrad
Copy link
Member

jngrad commented Mar 31, 2021

please don't merge it yet, we're looking into a simplification using a python reflection

@jngrad
Copy link
Member

jngrad commented Mar 31, 2021

The LBSlice now returns numpy arrays as array_locked. Properties are generated automatically.
The broken LBSlice.boundary raise assertion check is now fixed.

@jngrad
Copy link
Member

jngrad commented Mar 31, 2021

I accidentally pushed the python branch instead of fix-4143 to KaiserMartin's fork, and now GitHub rejects further pushes:

$ git push -f KaiserMartin fix-4143:python
X11 forwarding request failed on channel 0
Enumerating objects: 99, done.
Counting objects: 100% (99/99), done.
Delta compression using up to 32 threads
Compressing objects: 100% (88/88), done.
Writing objects: 100% (88/88), 17.57 KiB | 1.46 MiB/s, done.
Total 88 (delta 71), reused 0 (delta 0)
remote: Resolving deltas: 100% (71/71), completed with 11 local objects.
To github.com:KaiserMartin/espresso.git
 ! [remote rejected]     fix-4143 -> python (permission denied)
error: failed to push some refs to 'git@github.com:KaiserMartin/espresso.git'

GitHub also closed the PR using my username. Moving over to #4195. Sorry for the inconvenience.

@jngrad jngrad removed this from the Espresso 4.2 milestone Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement slicing support for LB
4 participants