Skip to content

Commit

Permalink
Refactor slow-running benchmark to slow_benchmarks directory
Browse files Browse the repository at this point in the history
  • Loading branch information
brocksam committed Oct 17, 2022
1 parent c1c8251 commit 6ee3acb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
34 changes: 1 addition & 33 deletions benchmarks/core/diff.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Benchmarks for symbolic differentiation."""

import pathlib

from sympy import sympify
from sympy import exp, sin, symbols, tan, Matrix


class GriewankBabyExampleDerivatives:
Expand Down Expand Up @@ -49,33 +47,3 @@ def setup(self):
def time_jacobian(self):
"""Time differentation of the lighthouse example."""
self.G = self.y.jacobian(self.x)


class Gait2DDerivatives:
"""Large real-world example equations of motion in 42 variables.
The equations of motion (EoMs) are derived from the Gait2D dynamic model of
gait (see here: https://github.com/csu-hmc/gait2d). This specific benchmark,
involving the derivation of the 18x42 Jacobian matrix, was highlighted in
SymPy issue #8191 (see here: https://github.com/sympy/sympy/issues/8191).
"""

def setup(self):
"""Read the equation of motion and variables from artifact files.
The 18 equations of motion are specified in `dis_eom.txt` while the 42
variables are specified in `partials.txt`.
"""
artifacts_dir_path = pathlib.Path(__file__).parents[0] / "artifacts"
dis_eom_path = pathlib.Path(artifacts_dir_path, "dis_eom.txt")
with open(dis_eom_path, "r") as A_file:
self.A = sympify(A_file.read())
partials_path = pathlib.Path(artifacts_dir_path, "partials.txt")
with open(partials_path, "r") as x_file:
self.x = sympify(x_file.read())

def time_jacobian(self):
"""Time differentiation to construct the 18x42 Jacobian matrix."""
self.A.jacobian(self.x)
Empty file.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions slow_benchmarks/core/diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Benchmarks for symbolic differentiation."""

import pathlib

from sympy import sympify


class Gait2DDerivatives:
"""Large real-world example equations of motion in 42 variables.
The equations of motion (EoMs) are derived from the Gait2D dynamic model of
gait (see here: https://github.com/csu-hmc/gait2d). This specific benchmark,
involving the derivation of the 18x42 Jacobian matrix, was highlighted in
SymPy issue #8191 (see here: https://github.com/sympy/sympy/issues/8191).
"""

def setup(self):
"""Read the equation of motion and variables from artifact files.
The 18 equations of motion are specified in `dis_eom.txt` while the 42
variables are specified in `partials.txt`. Copies of both `dis_eom.txt`
and `partials.txt` are in the `artifacts` subdirectory.
"""
artifacts_dir_path = pathlib.Path(__file__).parents[0] / "artifacts"
dis_eom_path = pathlib.Path(artifacts_dir_path, "dis_eom.txt")
with open(dis_eom_path, "r") as A_file:
self.A = sympify(A_file.read())
partials_path = pathlib.Path(artifacts_dir_path, "partials.txt")
with open(partials_path, "r") as x_file:
self.x = sympify(x_file.read())

def time_jacobian(self):
"""Time differentiation to construct the 18x42 Jacobian matrix."""
self.A.jacobian(self.x)

0 comments on commit 6ee3acb

Please sign in to comment.