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

update get dimensionality method. #361

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
56 changes: 21 additions & 35 deletions mdsuite/utils/meta_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def is_jsonable(x: dict) -> bool:


def join_path(a, b):
"""Join a and b and make sure to use forward slashes
"""
Join a and b and make sure to use forward slashes

Parameters
----------
Expand All @@ -94,12 +95,15 @@ def join_path(a, b):

def get_dimensionality(box: list) -> int:
"""
Calculate the dimensionality of the experiment box
Calculate the dimensionality of the experiment box.
PythonFZ marked this conversation as resolved.
Show resolved Hide resolved

Run np where to check where in the box a non-zero number occurs. Set these numbers
to 1 and sum over them.

Parameters
----------
box : list
box array of the experiment of the form [x, y, z]
box array of the experiment of the form [x, y, z] shape (N,)

Returns
-------
Expand All @@ -108,25 +112,7 @@ def get_dimensionality(box: list) -> int:
make sense just yet)
"""

# Check if the x, y, or z entries are empty, i.e. 2 dimensions
if box[0] == 0 or box[1] == 0 or box[2] == 0:
if (
box[0] == 0
and box[1] == 0
or box[0] == 0
and box[2] == 0
or box[1] == 0
and box[2] == 0
):
dimensions = 1
else:
dimensions = 2

# Other option is 3 dimensions.
else:
dimensions = 3

return dimensions
return np.where(box != 0, 0, 1, 0).sum()
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems thre has actually been a test for this the whole time. One of the first added.

def test_get_dimensionality(self):
        """
        Test the get_dimensionality method.
        Returns
        -------
        assert that for all choices of dimension array the correct dimension comes out.
        """
        one_d = [1, 0, 0]
        two_d = [1, 1, 0]
        three_d = [1, 1, 1]
        assert get_dimensionality(one_d) == 1
        assert get_dimensionality(two_d) == 2
        assert get_dimensionality(three_d) == 3



def get_machine_properties() -> dict:
Expand Down Expand Up @@ -223,11 +209,11 @@ def optimize_batch_size(
computer_statistics = get_machine_properties() # Get computer statistics
file_size = os.path.getsize(filepath) # Get the size of the file
database_memory = (
0.1 * computer_statistics["memory"]
0.1 * computer_statistics["memory"]
) # We take 10% of the available memory

memory_per_configuration = (
file_size / number_of_configurations
file_size / number_of_configurations
) # get the memory per configuration
initial_batch_number = int(
database_memory / (5 * memory_per_configuration)
Expand Down Expand Up @@ -330,7 +316,7 @@ def wrap(*args, **kw):


def apply_savgol_filter(
data: list, order: int = 2, window_length: int = 17
data: list, order: int = 2, window_length: int = 17
) -> np.ndarray:
"""
Apply a savgol filter for function smoothing
Expand Down Expand Up @@ -380,15 +366,15 @@ def closest_point(data: np.ndarray, value: float):


def golden_section_search(
data: np.array,
a: float,
b: float,
tol: float = 1e-5,
h: float = None,
c: float = None,
d: float = None,
fc: float = None,
fd: float = None,
data: np.array,
a: float,
b: float,
tol: float = 1e-5,
h: float = None,
c: float = None,
d: float = None,
fc: float = None,
fd: float = None,
) -> tuple:
"""
Perform a golden-section search for function minimums
Expand Down Expand Up @@ -492,7 +478,7 @@ def split_array(data: np.array, condition: np.array) -> list:
initial_split = [data[condition], data[~condition]] # attempt to split the array

if (
len(initial_split[1]) == 0
len(initial_split[1]) == 0
): # if the condition is never met, return only the raw tensor_values
return list([data[condition]])
else: # else return the whole array
Expand Down