Skip to content

Commit

Permalink
prevent unused vars in jacobians (#239)
Browse files Browse the repository at this point in the history
* prevent unused vars in jacobians
  • Loading branch information
MauriceHendrix committed Apr 14, 2022
1 parent cb5d1b9 commit 2c4f4bb
Show file tree
Hide file tree
Showing 6 changed files with 2,476 additions and 8 deletions.
8 changes: 3 additions & 5 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Release 0.9.6
- This release fixes a bug printing large integers, in some environments: Large numbers such as 8.034023767017109e+27 whch were actually ints would be printed as an the int 8034023767017108950029959168 and then the C++ compiler would complain as that's more than the maximum int value. This has been fixed by only printing ints as ints if they are `MIN_INT < number < MAX_INT` else we print them as a float (and we get the sceintific notation).

# Release 0.9.6 (yanked)
# Release 0.9.8
- Fixed an issue with unused variables appearing in common terms in jacobians.
- Fixes a bug printing large integers, in some environments: Large numbers such as 8.034023767017109e+27 whch were actually ints would be printed as an the int 8034023767017108950029959168 and then the C++ compiler would complain as that's more than the maximum int value. This has been fixed by only printing ints as ints if they are `MIN_INT < number < MAX_INT` else we print them as a float (and we get the sceintific notation).
- Fixed tests to pass with sympy 1.10 and required latest cellmlmanip, which also workes with sympy1.10. Updated sympy requirement to be >=1.9, < 1.11
- This release was yanked due to a bug printing large integers

# Release 0.9.5
- Corrected a type in the generated output for `--rush-larsen-c`
Expand Down
15 changes: 13 additions & 2 deletions chaste_codegen/_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,25 @@ def format_jacobian(jacobian_equations, jacobian_matrix, printer, print_rhs,
assert isinstance(printer, Printer), 'Expecting printer to be a cellmlmanip.printer.Printer'
assert callable(print_rhs), 'Expecting print_rhs to be a callable'

equations = [{'lhs': printer.doprint(eq[0]), 'rhs': print_rhs(eq[0], eq[1]), 'sympy_lhs': eq[0],
'sympy_rhs': eq[1]} for eq in jacobian_equations]
symbols_used = set()
rows, cols = jacobian_matrix.shape
jacobian = []
for i in range(cols if swap_inner_outer_index else rows):
for j in range(rows if swap_inner_outer_index else cols):
matrix_entry = jacobian_matrix[j, i] if swap_inner_outer_index else jacobian_matrix[i, j]
if not skip_0_entries or matrix_entry != 0:
symbols_used.update(matrix_entry.free_symbols)
jacobian.append({'i': j if swap_inner_outer_index else i, 'j': i if swap_inner_outer_index else j,
'entry': printer.doprint(matrix_entry)})

num_symbols = 0
while num_symbols != len(symbols_used):
num_symbols = len(symbols_used)
for eq in jacobian_equations:
if eq[0] in symbols_used:
symbols_used.update(eq[1].free_symbols)

equations = [{'lhs': printer.doprint(eq[0]), 'rhs': print_rhs(eq[0], eq[1]), 'sympy_lhs': eq[0],
'sympy_rhs': eq[1]} for eq in jacobian_equations if eq[0] in symbols_used]

return equations, jacobian
Loading

0 comments on commit 2c4f4bb

Please sign in to comment.