Battery Pack 18650 Open Ended
Source: examples/grammar/battery_pack_18650_open_ended.py
Introduction
Build and evaluate a feasible open-ended 4S4P-equivalent battery graph.
Technical Implementation
This page is generated from the top-of-file module docstring and the example source code. The full script is included below for direct inspection.
1from __future__ import annotations
2
3import design_research_problems as derp
4
5
6def main() -> None:
7 """Build a feasible 4S4P-equivalent explicit battery graph and evaluate it.
8
9 Raises:
10 RuntimeError: If the constructed example pack evaluates as infeasible.
11 """
12
13 # Load the open-ended battery grammar and start from its one-cell seed state.
14 problem = derp.get_problem("battery_pack_18650_open_ended")
15 state = problem.initial_state()
16 stage_input_terminal_id = state.pack_negative_terminal_id
17 stage_output_terminal_id = state.pack_positive_terminal_id
18
19 # First, fill out the remaining three parallel cells in stage 0. Each add_cell
20 # action inserts a new physical cell and immediately ties both of its leads into
21 # the existing circuit by naming the terminals it should connect to.
22 for branch_index in range(1, 4):
23 state = problem.add_cell(
24 state,
25 x=0,
26 y=branch_index,
27 z=0,
28 connect_negative_to_terminal_id=stage_input_terminal_id,
29 connect_positive_to_terminal_id=stage_output_terminal_id,
30 )
31
32 # Then grow the pack stage by stage. The first cell in each new stage extends
33 # the series chain and promotes its new positive lead to be the pack output.
34 # The remaining three cells for that stage are added in parallel between the
35 # previous stage output bus and the new stage output bus.
36 for stage_index in range(1, 4):
37 previous_stage_output_terminal_id = stage_output_terminal_id
38 state = problem.add_cell(
39 state,
40 x=stage_index,
41 y=0,
42 z=0,
43 connect_negative_to_terminal_id=previous_stage_output_terminal_id,
44 use_positive_as_pack_terminal=True,
45 )
46 stage_output_terminal_id = state.pack_positive_terminal_id
47 for branch_index in range(1, 4):
48 state = problem.add_cell(
49 state,
50 x=stage_index,
51 y=branch_index,
52 z=0,
53 connect_negative_to_terminal_id=previous_stage_output_terminal_id,
54 connect_positive_to_terminal_id=stage_output_terminal_id,
55 )
56
57 print(problem.metadata.problem_id)
58 print(f"{len(state.cells)} cells with {len(state.connections)} interconnects")
59 try:
60 # The evaluator validates the explicit graph, reduces it to circuit nets, and
61 # simulates the resulting pack through the shared battery backend.
62 evaluation = problem.evaluate(state)
63 except derp.MissingOptionalDependencyError as exc:
64 print(exc)
65 return
66 if not evaluation.is_feasible:
67 raise RuntimeError("The open-ended battery example should evaluate to a feasible design.")
68 print(evaluation.topology_kind, evaluation.is_feasible, round(evaluation.design_volume, 2))
69
70
71if __name__ == "__main__":
72 main()
Expected Results
Run Command
PYTHONPATH=src python3 examples/grammar/battery_pack_18650_open_ended.py
Run the command shown below from repository root. Output should summarize the problem setup, a baseline solution, or diagnostic values relevant to this example.