Skip to content

Commit

Permalink
Post merge updates for power costs, example
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyPlanden committed Oct 11, 2024
1 parent ab4586b commit 371ae0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions examples/scripts/maximising_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@
optim = pybop.XNES(
cost, verbose=True, allow_infeasible_solutions=False, max_iterations=10
)
x, final_cost = optim.run()
print("Estimated parameters:", x)
results = optim.run()
print("Estimated parameters:", results.x)
print(f"Initial gravimetric power density: {cost1(optim.x0):.2f} W.kg-1")
print(f"Optimised gravimetric power density: {cost1(x):.2f} W.kg-1")
print(f"Optimised gravimetric power density: {cost1(results.x):.2f} W.kg-1")
print(f"Initial volumetric power density: {cost2(optim.x0):.2f} W.m-3")
print(f"Optimised volumetric power density: {cost2(x):.2f} W.m-3")
print(f"Optimised discharge rate: {x[-1]:.2f} A = {x[-1]/nominal_capacity:.2f} C")
print(f"Optimised volumetric power density: {cost2(results.x):.2f} W.m-3")
print(
f"Optimised discharge rate: {results.x[-1]:.2f} A = {results.x[-1]/nominal_capacity:.2f} C"
)

# Plot the timeseries output
pybop.quick_plot(problem, problem_inputs=x, title="Optimised Comparison")
pybop.quick_plot(problem, problem_inputs=results.x, title="Optimised Comparison")

# Plot the cost landscape with optimisation path
pybop.plot2d(optim, steps=5)
6 changes: 4 additions & 2 deletions pybop/costs/design_costs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

import numpy as np

from pybop.costs.base_cost import BaseCost
Expand Down Expand Up @@ -168,7 +170,7 @@ class GravimetricPowerDensity(DesignCost):
The length of time (seconds) over which the power should be sustained.
"""

def __init__(self, problem, target_time: int = 3600):
def __init__(self, problem, target_time: Union[int, float] = 3600):
super().__init__(problem)
self.target_time = target_time

Expand Down Expand Up @@ -231,7 +233,7 @@ class VolumetricPowerDensity(DesignCost):
The length of time (seconds) over which the power should be sustained.
"""

def __init__(self, problem, target_time: int = 3600):
def __init__(self, problem, target_time: Union[int, float] = 3600):
super().__init__(problem)
self.target_time = target_time

Expand Down

0 comments on commit 371ae0c

Please sign in to comment.