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

Example powersystem.py doesn't work at all #1470

Open
dietmarwo opened this issue Sep 7, 2022 · 1 comment
Open

Example powersystem.py doesn't work at all #1470

dietmarwo opened this issue Sep 7, 2022 · 1 comment

Comments

@dietmarwo
Copy link
Contributor

Steps to reproduce

  1. pip install nevergrad
  2. git clone git@github.com:facebookresearch/nevergrad.git
  3. cd nevergrad/examples
  4. python powersystem.py
  5. using anaconda python 3.9 on Linux Mint 20.3.

Observed Results

  • What happened? This could be a description, log output, etc.

ana39/lib/python3.9/site-packages/nevergrad/optimization/base.py:146: InefficientSettingsWarning: num_workers = 10 > 1 is suboptimal when run sequentially
warnings.warn(msg, e)
Traceback (most recent call last):
File "/home/xxx/sich/examples/powersystem.py", line 43, in
optimizer.minimize(power_system_loss)
File "/home/xxx/ana39/lib/python3.9/site-packages/nevergrad/optimization/base.py", line 641, in minimize
result = job.result()
File "/home/xxx/ana39/lib/python3.9/site-packages/nevergrad/optimization/utils.py", line 137, in result
self._result = self.func(*self.args, **self.kwargs)
File "/home/xxx/ana39/lib/python3.9/site-packages/nevergrad/functions/base.py", line 119, in call
return self.function(*args, **kwargs)
File "/home/xxx/ana39/lib/python3.9/site-packages/nevergrad/functions/powersystems/core.py", line 129, in _simulate_power_system
agent.set_parameters(array)
File "/home/xxx/ana39/lib/python3.9/site-packages/nevergrad/functions/powersystems/core.py", line 37, in set_parameters
raise ValueError(f"length = {weights.size} instead of {self.dimension}: {weights}.")
ValueError: length = 7560 instead of 1260: [-0.73698052 1.41931025 1.34390607 ... -0.79129847 -0.77101758
-0.6903909 ].

Expected Results

  • What did you expect to happen?

Expected "optimizer.minimize(power_system_loss)" to perform some optimization and
"power_system_loss.make_plots" to show some plots.

As it is the one and only nevergrad example the observed result is a bit disappointing.

@Elcomiqu321
Copy link

`import nevergrad as ng
from nevergrad.functions.powersystems.core import PowerSystem

budget = 3500
width = 6
depth = 6
num_dams = 6
year_to_day_ratio = 0.5
back_to_normal = 0.5
num_thermal_plants = 6
constant_to_year_ratio = 4.0

power_system_loss = PowerSystem(
num_dams=num_dams,
depth=depth,
width=width,
year_to_day_ratio=year_to_day_ratio,
back_to_normal=back_to_normal,
num_thermal_plants=num_thermal_plants,
constant_to_year_ratio=constant_to_year_ratio,
)

added line:

param = int(power_system_loss.dimension/power_system_loss.num_dams)

changed 'parametrization=power_system_loss.dimension' in the optimizer parameters:

optimizer = ng.optimizers.SplitOptimizer(
parametrization=param, budget=budget, num_workers=1
)

optimizer.minimize(power_system_loss)
power_system_loss(optimizer.provide_recommendation().value)
power_system_loss.make_plots(
f"ps_{num_dams}dams_{depth}_{width}_ytdr{year_to_day_ratio}_btn{back_to_normal}"
f"_num_thermal_plants{num_thermal_plants}_ctyr{constant_to_year_ratio}_budget{budget}.png"
)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants