From c15713181129c1104009e2036189dadbaa8bfebc Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 20 Aug 2026 21:21:27 +0000 Subject: [PATCH] maintenance: raw-string the LaTeX-carrying docstrings Non-raw docstrings containing LaTeX are corrupted by Python's escape handling. Two distinct failure classes, and only the first is visible: warned `\s`, `\l`, `\[` ... escapes Python does NOT recognise. It leaves them literal but emits SyntaxWarning on every compile/import, and they are slated to become a SyntaxError. silent `\t` in `\theta`, `\f` in `\frac`, `\r` in `\rm`, `\b` in `\beta`. Escapes Python DOES recognise: the value is corrupted with NO diagnostic at all. `\theta_E` was literally TAB + "heta_E". 13 literals across 4 files get the `r` prefix. Both sweeps now return zero. Verified, not assumed: - Runtime values: 7 corruptions repaired, 0 other changes. Each changed literal's value was compared HEAD vs worktree; the prefix may only ever REMOVE corruption, never alter a string otherwise. - Regenerated with autohands: markdown/, llms-full.txt and workspace_index.json are byte-identical. The only notebook delta is the four `plt.ylabel` labels, which are runtime strings in CODE cells, so the source change is meant to show there. Prose cells are unchanged. Deliberate escapes were left alone: `print("\nInfo:")` and friends keep their real newlines, and `" \\[-2pt]"` keeps its already-escaped LaTeX line break. The prefix was only applied where every backslash sits in a LaTeX context ($...$, \(...\), \[...\], \begin{}...\end{}, or a markdown code span). --- .../tutorial_4_why_modeling_is_hard.ipynb | 8 ++++---- scripts/chapter_1_introduction/tutorial_1_models.py | 4 ++-- .../chapter_1_introduction/tutorial_2_fitting_data.py | 10 +++++----- .../tutorial_3_non_linear_search.py | 2 +- .../tutorial_4_why_modeling_is_hard.py | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb b/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb index 1700b37..45d83bc 100644 --- a/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb +++ b/notebooks/chapter_1_introduction/tutorial_4_why_modeling_is_hard.ipynb @@ -623,7 +623,7 @@ "plt.plot(xvalues, normalized_residual_map, color=\"k\")\n", "plt.title(f\"Normalized Residuals (log likelihood = {result.log_likelihood})\")\n", "plt.xlabel(\"x values of profile\")\n", - "plt.ylabel(\"Normalized Residuals ($\\sigma$)\")\n", + "plt.ylabel(r\"Normalized Residuals ($\\sigma$)\")\n", "plt.show()\n", "plt.clf()\n", "plt.close()" @@ -834,7 +834,7 @@ "plt.plot(xvalues, normalized_residual_map, color=\"k\")\n", "plt.title(f\"Normalized Residuals (log likelihood = {result.log_likelihood})\")\n", "plt.xlabel(\"x values of profile\")\n", - "plt.ylabel(\"Normalized Residuals ($\\sigma$)\")\n", + "plt.ylabel(r\"Normalized Residuals ($\\sigma$)\")\n", "plt.show()\n", "plt.clf()\n", "plt.close()" @@ -986,7 +986,7 @@ "plt.plot(xvalues, normalized_residual_map, color=\"k\")\n", "plt.title(f\"Normalized Residuals (log likelihood = {result.log_likelihood})\")\n", "plt.xlabel(\"x values of profile\")\n", - "plt.ylabel(\"Normalized Residuals ($\\sigma$)\")\n", + "plt.ylabel(r\"Normalized Residuals ($\\sigma$)\")\n", "plt.show()\n", "plt.clf()\n", "plt.close()" @@ -1148,7 +1148,7 @@ "plt.plot(xvalues, normalized_residual_map, color=\"k\")\n", "plt.title(f\"Normalized Residuals (log likelihood = {result.log_likelihood})\")\n", "plt.xlabel(\"x values of profile\")\n", - "plt.ylabel(\"Normalized Residuals ($\\sigma$)\")\n", + "plt.ylabel(r\"Normalized Residuals ($\\sigma$)\")\n", "plt.show()\n", "plt.clf()\n", "plt.close()" diff --git a/scripts/chapter_1_introduction/tutorial_1_models.py b/scripts/chapter_1_introduction/tutorial_1_models.py index ee92d05..815e4a5 100644 --- a/scripts/chapter_1_introduction/tutorial_1_models.py +++ b/scripts/chapter_1_introduction/tutorial_1_models.py @@ -76,7 +76,7 @@ import autofit as af -""" +r""" __Paths__ PyAutoFit assumes the current working directory is /path/to/HowToFit/ on your hard-disk (or in Colab). @@ -288,7 +288,7 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: plt.show() plt.clf() -""" +r""" __Complex Models__ The code above may seem like a lot of steps just to create an instance of the `Gaussian` class. Couldn't we have diff --git a/scripts/chapter_1_introduction/tutorial_2_fitting_data.py b/scripts/chapter_1_introduction/tutorial_2_fitting_data.py index 4be9b87..7ae5250 100644 --- a/scripts/chapter_1_introduction/tutorial_2_fitting_data.py +++ b/scripts/chapter_1_introduction/tutorial_2_fitting_data.py @@ -286,7 +286,7 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: plt.show() plt.clf() -""" +r""" __Normalized Residuals__ Another method to quantify and visualize the quality of the fit is using the normalized residual map, also known as @@ -312,7 +312,7 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: plt.show() plt.clf() -""" +r""" __Chi Squared__ Next, we define the `chi_squared_map`, which is obtained by squaring the `normalized_residual_map` and serves as a @@ -335,7 +335,7 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: plt.show() plt.clf() -""" +r""" Now, we consolidate all the information in our `chi_squared_map` into a single measure of goodness-of-fit called `chi_squared`. @@ -350,7 +350,7 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: chi_squared = np.sum(chi_squared_map) print("Chi-squared = ", chi_squared) -""" +r""" The lower the `chi_squared`, the fewer residuals exist between the model's fit and the data, indicating a better overall fit! @@ -375,7 +375,7 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray: """ noise_normalization = np.sum(np.log(2 * np.pi * noise_map**2.0)) -""" +r""" __Likelihood__ From the `chi_squared` and `noise_normalization`, we can define a final goodness-of-fit measure known as diff --git a/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py b/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py index 316dd78..b4b7bf3 100644 --- a/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py +++ b/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py @@ -1,4 +1,4 @@ -""" +r""" Tutorial 3: Non Linear Search ============================= diff --git a/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py b/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py index 88d2b84..03bb035 100644 --- a/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py +++ b/scripts/chapter_1_introduction/tutorial_4_why_modeling_is_hard.py @@ -434,7 +434,7 @@ def model_data_from_instance(self, instance): plt.plot(xvalues, normalized_residual_map, color="k") plt.title(f"Normalized Residuals (log likelihood = {result.log_likelihood})") plt.xlabel("x values of profile") -plt.ylabel("Normalized Residuals ($\sigma$)") +plt.ylabel(r"Normalized Residuals ($\sigma$)") plt.show() plt.clf() plt.close() @@ -601,7 +601,7 @@ def model_data_from_instance(self, instance): plt.plot(xvalues, normalized_residual_map, color="k") plt.title(f"Normalized Residuals (log likelihood = {result.log_likelihood})") plt.xlabel("x values of profile") -plt.ylabel("Normalized Residuals ($\sigma$)") +plt.ylabel(r"Normalized Residuals ($\sigma$)") plt.show() plt.clf() plt.close() @@ -709,7 +709,7 @@ def model_data_from_instance(self, instance): plt.plot(xvalues, normalized_residual_map, color="k") plt.title(f"Normalized Residuals (log likelihood = {result.log_likelihood})") plt.xlabel("x values of profile") -plt.ylabel("Normalized Residuals ($\sigma$)") +plt.ylabel(r"Normalized Residuals ($\sigma$)") plt.show() plt.clf() plt.close() @@ -817,12 +817,12 @@ def model_data_from_instance(self, instance): plt.plot(xvalues, normalized_residual_map, color="k") plt.title(f"Normalized Residuals (log likelihood = {result.log_likelihood})") plt.xlabel("x values of profile") -plt.ylabel("Normalized Residuals ($\sigma$)") +plt.ylabel(r"Normalized Residuals ($\sigma$)") plt.show() plt.clf() plt.close() -""" +r""" If you repeat the fit multiple times, you will find that the model-fit is more likely to produce a good fit than previously.