Skip to content

Commit

Permalink
New version of black (#36)
Browse files Browse the repository at this point in the history
* ran black

* doc language

* allow docs to warn

* fixed test

* more samples in stocastic test
  • Loading branch information
tommyod authored Feb 20, 2023
1 parent c2c41bb commit 68c1cb6
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 41 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ sphinx>=1.4
ipykernel
nbsphinx
matplotlib
pandoc
1 change: 0 additions & 1 deletion streprogen/diet.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class Meal:
# This means that a baseline

def __init__(self, name, foods, discrete=True):

self.name = name
self.foods = foods
self.discrete = discrete
Expand Down
1 change: 0 additions & 1 deletion streprogen/exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def _simple_attributes(self):
attributes.remove("shift")

for attr_name in attributes:

# Skip private members
if attr_name.startswith("_"):
continue
Expand Down
2 changes: 0 additions & 2 deletions streprogen/mealplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, *args, **kwds):


class Mealplan:

TEMPLATE_DIR = path.join(path.dirname(__file__), "templates")
TEMPLATE_NAMES = {extension: "mealplan_template." + extension for extension in ["txt"]}

Expand Down Expand Up @@ -170,7 +169,6 @@ def format_qntity(qnty):
return qnty

for day_num in range(num_days):

x_day = [x[i][day_num] for i in range(num_meals)]

result = [(meal, qnty) for (meal, qnty) in zip(self.meals, x_day) if qnty > 0]
Expand Down
6 changes: 1 addition & 5 deletions streprogen/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def optimize_sets(reps, intensities, reps_goal, intensities_goal):
z = [z_j.solution_value() for z_j in z]

# Assert that the property of the z's hold
for (x_j, z_j) in zip(x, z):
for x_j, z_j in zip(x, z):
if z_j == 1:
assert x_j >= 1
else:
Expand Down Expand Up @@ -510,7 +510,6 @@ def optimize_mealplan(
# OBJECTIVE FUNCTION TERM 2: Deviation from nutrients (on a daily basis)
for j in range(num_days):
for macro, (low, high) in dietary_constraints.items():

# No point in adding any constraints if it's None
if low is None and high is None:
continue
Expand Down Expand Up @@ -546,7 +545,6 @@ def optimize_mealplan(
upper = solver.NumVar(0, INF, "upper_kcal_{}".format(j))

for i, meal in enumerate(meals):

solver.Add(lower <= x[i][j] * meal.kcal + (1 - z[i][j]) * M2)
solver.Add(upper >= x[i][j] * meal.kcal)

Expand All @@ -562,7 +560,6 @@ def optimize_mealplan(

# HARD CONSTRAINT 2: Number of times a food is used
for i, (meal, (low, high)) in enumerate(zip(meals, meals_limits)):

times_used = sum(z[i])
assert len(z[i]) == num_days

Expand All @@ -585,7 +582,6 @@ def optimize_mealplan(
solver.Minimize(objective_function)
result_status = solver.Solve()
if result_status == solver.INFEASIBLE:

if first_call:
params["first_call"] = False

Expand Down
10 changes: 3 additions & 7 deletions streprogen/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def __init__(
reps_to_intensity_func: typing.Callable[[int], float] = None,
verbose: bool = False,
):

"""Initialize a new program.
Expand Down Expand Up @@ -399,7 +398,6 @@ def _validate(self):

# Validate the exercises
for exercise in self._yield_exercises():

if isinstance(exercise, StaticExercise):
continue

Expand Down Expand Up @@ -571,8 +569,7 @@ def render(self, validate=True):
# Render the dynamic exercises
# --------------------------------

for (week, day, dyn_ex) in self._yield_week_day_dynamic():

for week, day, dyn_ex in self._yield_week_day_dynamic():
# Set min and max reps from program, if not set on exercise
min_reps = dyn_ex.min_reps
max_reps = dyn_ex.max_reps
Expand Down Expand Up @@ -760,7 +757,7 @@ def to_txt(self, verbose=False):
# If rendered, find the length of the longest '6 x 75kg'-type string
max_ex_scheme = 0
if self._rendered:
for (week, day, dynamic_ex) in self._yield_week_day_dynamic():
for week, day, dynamic_ex in self._yield_week_day_dynamic():
lengths = [len(s) for s in self._rendered[week][day][dynamic_ex]["strings"]]
max_ex_scheme = max(max_ex_scheme, max(lengths))

Expand Down Expand Up @@ -800,7 +797,7 @@ def to_tex(self, text_size="large", table_width=5, clear_pages=False):
# If rendered, find the length of the longest '6 x 75kg'-type string
max_ex_scheme = 0
if self._rendered:
for (week, day, dynamic_ex) in self._yield_week_day_dynamic():
for week, day, dynamic_ex in self._yield_week_day_dynamic():
lengths = [len(s) for s in self._rendered[week][day][dynamic_ex]["strings"]]
max_ex_scheme = max(max_ex_scheme, max(lengths))

Expand Down Expand Up @@ -832,7 +829,6 @@ def __str__(self):
pytest.main(args=[".", "--doctest-modules", "-v", "--capture=sys"])

if __name__ == "__main__":

from streprogen import Program

def rep_scaler_func(week, *args):
Expand Down
1 change: 0 additions & 1 deletion streprogen/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def sample_markov_ladder(probabilities, structure=None):

k, n = len(structure), len(probabilities)
while True:

# Assemble probabilities
left_probs = [structure[i] / probabilities[state] for i in reversed(range(1, min(k, state + 1)))]
right_probs = [structure[i] / probabilities[state] for i in range(1, min(k, n - state))]
Expand Down
15 changes: 2 additions & 13 deletions streprogen/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def curl_func(week):
program = Program("My first program!", duration=8)

with program.Day():

program.DynamicExercise("Bench press", 60, 65)
program.DynamicExercise("Squats", 80, 85)
program.StaticExercise("Curls", curl_func)
Expand All @@ -104,9 +103,7 @@ def curl_func(week):

@pytest.mark.parametrize("period", [0, 1])
def test_progression_periods(period):

for week in range(1, 8 + 1):

ans = progression_sawtooth(
week,
start_weight=1.0,
Expand Down Expand Up @@ -139,7 +136,6 @@ def test_progression_periods(period):
list(itertools.product([progression_sawtooth, progression_sinusoidal], [1, 2, 3, 4, 5])),
)
def test_progression_means(func, period):

weeks = list(range(1, period + 1))
target = 42

Expand Down Expand Up @@ -212,7 +208,6 @@ def test_program_not_mutated_after_rendering():

class TestProgressInformation:
def test_progress_information_override_weights(self):

program = Program(name="MyProgram", duration=10, percent_inc_per_week=10)
with program.Day("A"):
squat = program.DynamicExercise("Squats", start_weight=100, final_weight=150)
Expand All @@ -223,7 +218,6 @@ def test_progress_information_override_weights(self):
assert inc_week == 5 # Weight override program default

def test_progress_information_override_perc_inc(self):

program = Program(name="MyProgram", duration=10, percent_inc_per_week=1)
with program.Day("A"):
squat = program.DynamicExercise("Squats", start_weight=100, percent_inc_per_week=10)
Expand Down Expand Up @@ -266,7 +260,6 @@ def test_progress_information_calcs_from_program(self):
assert b_info == c_info

def test_progress_information_overspecified(self):

# Set some non-typical parameters
program = Program(name="MyProgram", duration=10)
with pytest.raises(ValueError, match="At most 2 out of 3 variables may be set"):
Expand Down Expand Up @@ -468,7 +461,6 @@ def test_setting_optimization_params(self):

class TestShiftingDynExercises:
def test_shifting_zero(self):

program1 = Program("My first program!", duration=8, round_to=1)
with program1.Day():
program1.DynamicExercise("Bench press", start_weight=100)
Expand All @@ -483,7 +475,6 @@ def test_shifting_zero(self):

@pytest.mark.parametrize("shift", [-3, -2, -1, 0, 1, 2, 3])
def test_shifting_k(self, shift):

program1 = Program("My first program!", duration=8, round_to=1)
with program1.Day():
program1.DynamicExercise("Bench press", start_weight=100)
Expand Down Expand Up @@ -528,13 +519,12 @@ def round_function(x):
program = Program("My first program!", duration=8)

with program.Day():

program.DynamicExercise("Bench press", 60, 65, round_to=2.5)
program.DynamicExercise("Squats", 80, 85, round_to=round_function)

program.render()

return True
assert True

def test_rounding_func_program(self):
"""Test that both functions and numbers work for rounding."""
Expand All @@ -546,7 +536,6 @@ def round_function(x):
program = Program("My first program!", duration=8, round_to=round_function)

with program.Day():

program.DynamicExercise("Bench press", 60, 65)
program.DynamicExercise("Squats", 80, 85)

Expand All @@ -557,7 +546,7 @@ def round_function(x):
for dyn_ex in day["exercises"]:
assert all(w % 4 == 0 for w in dyn_ex["weights"])

return True
assert True


if __name__ == "__main__":
Expand Down
2 changes: 0 additions & 2 deletions streprogen/tests/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@pytest.mark.parametrize("k, duration", [(0, 12), (0, 13), (3, 12), (3, 13)])
def test_progression_sinh(k, duration):

# Test first and last points
assert progression_sinh(1, 50, 100, 1, final_week=duration, k=k) == 50
assert progression_sinh(duration, 50, 100, 1, final_week=duration, k=k) == 100
Expand All @@ -22,7 +21,6 @@ def test_progression_sinh(k, duration):

@pytest.mark.parametrize("k, duration", [(0, 12), (0, 13), (3, 12), (3, 13)])
def test_progression_diffeq(k, duration):

# Test first and last points
assert progression_diffeq(1, 50, 100, 1, final_week=duration, k=k) == 50
assert progression_diffeq(duration, 50, 100, 1, final_week=duration, k=k) == 100
Expand Down
3 changes: 0 additions & 3 deletions streprogen/tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_repscheme_optimizer(reps_to_intensity_func, reps_goal, intensities_goal

@pytest.mark.parametrize("reps_slack", [0, 1, 2, 3, 4])
def test_repscheme_generator_reps_slack(reps_slack):

generator = RepSchemeGenerator(reps_slack=reps_slack)
sets = [3, 4, 5, 6, 7, 8]
for reps_goal in [15, 20, 25, 30]:
Expand All @@ -58,7 +57,6 @@ def test_repscheme_generator_reps_slack(reps_slack):

@pytest.mark.parametrize("max_unique", [1, 2, 3, 4])
def test_repscheme_generator_max_unique(max_unique):

generator = RepSchemeGenerator(max_unique=max_unique)
sets = [3, 4, 5, 6, 7, 8]
for reps_goal in [15, 20, 25, 30]:
Expand All @@ -69,7 +67,6 @@ def test_repscheme_generator_max_unique(max_unique):

@pytest.mark.parametrize("max_diff", [0, 1, 2, 3, 4])
def test_repscheme_generator_max_diff(max_diff):

generator = RepSchemeGenerator(max_diff=max_diff)
sets = [3, 4, 5, 6, 7, 8]
for reps_goal in [15, 20, 25, 30]:
Expand Down
6 changes: 2 additions & 4 deletions streprogen/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
],
)
def test_markov_ladder(probabilities, structure):

generator = sample_markov_ladder(probabilities, structure=structure)

# Scale after calling sampling, to test that normalization is not needed
probabilities = [p_i / sum(probabilities) for p_i in probabilities]

# Draw samples and normalize output probabilities
num_samples = 100_000
num_samples = 1_000_000
samples = itertools.islice(generator, num_samples)
counts = collections.Counter(samples)
output_probabilities = [counts[k] / num_samples for k in sorted(counts.keys())]
Expand All @@ -50,14 +49,13 @@ def test_markov_ladder(probabilities, structure):
],
)
def test_markov_loop(probabilities, structure):

generator = sample_markov_loop(probabilities, structure=structure)

# Scale after calling sampling, to test that normalization is not needed
probabilities = [p_i / sum(probabilities) for p_i in probabilities]

# Draw samples and normalize output probabilities
num_samples = 100_000
num_samples = 1_000_000
samples = itertools.islice(generator, num_samples)
counts = collections.Counter(samples)
output_probabilities = [counts[k] / num_samples for k in sorted(counts.keys())]
Expand Down

0 comments on commit 68c1cb6

Please sign in to comment.