Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
deploy:
runs-on: ubuntu-latest
needs: build
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'workflow_dispatch'
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
permissions:
pages: write
id-token: write
Expand Down
38 changes: 37 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,40 @@ license = "BSD-3-Clause"

[workspace.dependencies]
nalgebra = "0.34.1"
pyo3 = { version = "0.27.1", default-features = false, features = ["macros"] }
pyo3 = { version = "0.27.1", default-features = false, features = ["macros"] }

[workspace.lints.clippy]
# Enable pedantic lints for higher code quality standards
pedantic = { level = "deny", priority = -1 }

# Specific allows to reduce noise from pedantic
module_name_repetitions = "allow" # Common in large codebases
similar_names = "allow" # Scientific code often has x, y, z, etc.
must_use_candidate = "allow" # Too noisy for mathematical functions
cast_precision_loss = "allow" # Acceptable in numerical code (usize to f64)
cast_possible_truncation = "allow" # Acceptable when converting calculated values
cast_sign_loss = "allow" # Acceptable in constrained numerical contexts
cast_possible_wrap = "allow" # Acceptable in controlled numerical contexts

# Additional strict lints
missing_errors_doc = "warn"
missing_panics_doc = "warn"
missing_safety_doc = "warn"
undocumented_unsafe_blocks = "warn"

# Performance and correctness
inefficient_to_string = "warn"
manual_ok_or = "warn"
redundant_closure_for_method_calls = "warn"

# Complexity and style
cognitive_complexity = "warn"
too_many_lines = "warn"

# Selected nursery lints
option_if_let_else = "warn"
suboptimal_flops = "allow" # Suggested optimisations often reduce readability in tests

# Test-specific allows
float_cmp = "allow" # Exact float equality is standard in tests
cast_lossless = "allow" # i32 to f64 conversions in tests/benchmarks
Comment thread
BradyPlanden marked this conversation as resolved.
58 changes: 54 additions & 4 deletions docs/tutorials/notebooks/ode_fitting_diffsol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
}
},
"outputs": [],
"source": "# Import plotting utilities\nimport diffid\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom diffid.plotting import ode_fit"
"source": [
"# Import plotting utilities\n",
"import diffid\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from diffid.plotting import ode_fit"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -114,7 +120,34 @@
}
},
"outputs": [],
"source": "# Time points\nt_span = np.linspace(0, 4, 100)\n\n# True logistic growth solution with known parameters\n# y(t) = y0 * exp(r*t) / (1 + y0 * (exp(r*t) - 1) / k)\ny0 = 0.1\nr_true = 1.0\nk_true = 1.0\n\n# Generate clean data\nexp_rt = np.exp(r_true * t_span)\ny_data = y0 * exp_rt / (1 + y0 * (exp_rt - 1) / k_true)\n\n# Add some noise\nnp.random.seed(42)\nnoise_level = 0.01\ny_noisy = y_data + np.random.normal(0, noise_level, size=y_data.shape)\n\n# Diffid expects data as [time, observation] columns\ndata = np.column_stack((t_span, y_noisy))\n\nprint(f\"Generated {len(t_span)} data points\")\nprint(f\"Time range: [{t_span[0]:.2f}, {t_span[-1]:.2f}]\")\nprint(f\"Value range: [{y_noisy.min():.3f}, {y_noisy.max():.3f}]\")\nprint(f\"Noise level: {noise_level}\")\nprint(f\"\\nTrue parameters: r = {r_true}, k = {k_true}\")"
"source": [
"# Time points\n",
"t_span = np.linspace(0, 4, 100)\n",
"\n",
"# True logistic growth solution with known parameters\n",
"# y(t) = y0 * exp(r*t) / (1 + y0 * (exp(r*t) - 1) / k)\n",
"y0 = 0.1\n",
"r_true = 1.0\n",
"k_true = 1.0\n",
"\n",
"# Generate clean data\n",
"exp_rt = np.exp(r_true * t_span)\n",
"y_data = y0 * exp_rt / (1 + y0 * (exp_rt - 1) / k_true)\n",
"\n",
"# Add some noise\n",
"np.random.seed(42)\n",
"noise_level = 0.01\n",
"y_noisy = y_data + np.random.normal(0, noise_level, size=y_data.shape)\n",
"\n",
"# Diffid expects data as [time, observation] columns\n",
"data = np.column_stack((t_span, y_noisy))\n",
"\n",
"print(f\"Generated {len(t_span)} data points\")\n",
"print(f\"Time range: [{t_span[0]:.2f}, {t_span[-1]:.2f}]\")\n",
"print(f\"Value range: [{y_noisy.min():.3f}, {y_noisy.max():.3f}]\")\n",
"print(f\"Noise level: {noise_level}\")\n",
"print(f\"\\nTrue parameters: r = {r_true}, k = {k_true}\")"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -184,7 +217,24 @@
}
},
"outputs": [],
"source": "# Create builder\nbuilder = (\n diffid.DiffsolBuilder()\n .with_diffsl(dsl_model)\n .with_data(data)\n .with_tolerances(1e-6, 1e-8) # Relative and absolute tolerances\n .with_parameter(\"r\", 10.0) # Initial guess (deliberately wrong)\n .with_parameter(\"k\", 10.0) # Initial guess (deliberately wrong)\n .with_parallel(True) # Enable parallel evaluation\n)\n\nproblem = builder.build()\n\nprint(\"Problem built successfully!\")\nprint(\"\\nInitial parameter guesses: r = 50.0, k = 50.0\")\nprint(f\"(Far from true values: r = {r_true}, k = {k_true})\")"
"source": [
"# Create builder\n",
"builder = (\n",
" diffid.DiffsolBuilder()\n",
" .with_diffsl(dsl_model)\n",
" .with_data(data)\n",
" .with_tolerances(1e-6, 1e-8) # Relative and absolute tolerances\n",
" .with_parameter(\"r\", 10.0) # Initial guess\n",
" .with_parameter(\"k\", 10.0) # Initial guess\n",
" .with_parallel(True) # Enable parallel evaluation\n",
")\n",
"\n",
"problem = builder.build()\n",
"\n",
"print(\"Problem built successfully!\")\n",
"print(\"\\nInitial parameter guesses: r = 50.0, k = 50.0\")\n",
"print(f\"(Far from true values: r = {r_true}, k = {k_true})\")"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -513,4 +563,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion docs/tutorials/notebooks/optimisation_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
"\n",
"for name, result in results.items():\n",
" print(\n",
" f\"{name:<15} {str(result.success):<10} {result.value:<15.3e} \"\n",
" f\"{name:<15} {result.success!s:<10} {result.value:<15.3e} \"\n",
" f\"{result.iterations:<12} {result.evaluations}\"\n",
" )\n",
"\n",
Expand Down
Loading
Loading