Skip to content

Fatal crash in ipynb file #20789

@Matt-Ord

Description

@Matt-Ord

Summary

panic: Panicked at crates/ruff_notebook/src/notebook.rs:281:21 when checking `/workspaces/thesis_calculations/scripts/local_basis/alpha_dynamics.ipynb`: `Transformed content out of bounds (2610..2609) for cell at 1`
--> scripts/local_basis/alpha_dynamics.ipynb:1:1
info: This indicates a bug in Ruff.
info: If you could open an issue at https://github.com/astral-sh/ruff/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: Backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: <unknown>
  20: <unknown>
  21: start_thread
  22: clone


Found 1 error.
error: Panic during linting indicates a bug in Ruff. If you could open an issue at:

https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D

...with the relevant file contents, the `pyproject.toml` settings, and the stack trace above, we'd be very appreciative!

The file

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "775be936",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alpha Derivative\n"
     ]
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\lambda \\left(\\alpha - \\overline{\\alpha}\\right)$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\frac{i \\left(\\alpha \\text{hbar}^{2} - \\overline{\\alpha} \\text{hbar}^{2} + \\omega^{2} \\alpha m^{2} + \\omega^{2} m^{2} \\overline{\\alpha}\\right)}{2 m \\text{hbar}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\frac{\\sqrt{2} \\sqrt{\\lambda} \\left(\\xi(t) \\beta \\text{hbar}^{2} - \\xi(t) \\text{hbar}^{2} + \\beta \\overline{\\xi(t)} \\overline{\\beta} \\text{hbar}^{2} - \\beta \\overline{\\xi(t)} \\text{hbar}^{2} + 4 K_{B} T \\xi(t) \\beta m + 4 K_{B} T \\xi(t) m + 4 K_{B} T \\beta m \\overline{\\xi(t)} \\overline{\\beta} + 4 K_{B} T \\beta m \\overline{\\xi(t)}\\right)}{4 \\sqrt{K_{B} T} \\sqrt{m} \\left(\\beta \\overline{\\beta} - 1\\right) \\text{hbar}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\sqrt{2} \\left(\\alpha + \\overline{\\alpha}\\right)}{2}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\sqrt{2} i \\left(- \\alpha + \\overline{\\alpha}\\right) \\text{hbar}}{2}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{alpha: sqrt(2)*\\langle x \\rangle/2 + sqrt(2)*I*\\langle p \\rangle/(2*hbar), conjugate(alpha): sqrt(2)*\\langle x \\rangle/2 - sqrt(2)*I*\\langle p \\rangle/(2*hbar)}\n"
     ]
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\langle p \\rangle}{m} - \\frac{\\sqrt{\\lambda} \\left(\\xi(t) \\beta \\overline{\\beta} \\text{hbar}^{2} + \\xi(t) \\beta \\text{hbar}^{2} - \\xi(t) \\overline{\\beta} \\text{hbar}^{2} - \\xi(t) \\text{hbar}^{2} + \\beta \\overline{\\xi(t)} \\overline{\\beta} \\text{hbar}^{2} - \\beta \\overline{\\xi(t)} \\text{hbar}^{2} + \\overline{\\xi(t)} \\overline{\\beta} \\text{hbar}^{2} - \\overline{\\xi(t)} \\text{hbar}^{2} + 4 K_{B} T \\xi(t) \\beta m \\overline{\\beta} + 4 K_{B} T \\xi(t) \\beta m + 4 K_{B} T \\xi(t) m \\overline{\\beta} + 4 K_{B} T \\xi(t) m + 4 K_{B} T \\beta m \\overline{\\xi(t)} \\overline{\\beta} + 4 K_{B} T \\beta m \\overline{\\xi(t)} + 4 K_{B} T m \\overline{\\xi(t)} \\overline{\\beta} + 4 K_{B} T m \\overline{\\xi(t)}\\right)}{4 \\sqrt{K_{B} T} \\sqrt{m} \\left(\\beta \\overline{\\beta} - 1\\right) \\text{hbar}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - 2 \\lambda \\langle p \\rangle - \\langle x \\rangle \\omega^{2} m - \\frac{i \\sqrt{\\lambda} \\left(\\xi(t) \\beta \\overline{\\beta} \\text{hbar}^{2} - \\xi(t) \\beta \\text{hbar}^{2} - \\xi(t) \\overline{\\beta} \\text{hbar}^{2} + \\xi(t) \\text{hbar}^{2} - \\beta \\overline{\\xi(t)} \\overline{\\beta} \\text{hbar}^{2} + \\beta \\overline{\\xi(t)} \\text{hbar}^{2} + \\overline{\\xi(t)} \\overline{\\beta} \\text{hbar}^{2} - \\overline{\\xi(t)} \\text{hbar}^{2} + 4 K_{B} T \\xi(t) \\beta m \\overline{\\beta} - 4 K_{B} T \\xi(t) \\beta m + 4 K_{B} T \\xi(t) m \\overline{\\beta} - 4 K_{B} T \\xi(t) m - 4 K_{B} T \\beta m \\overline{\\xi(t)} \\overline{\\beta} - 4 K_{B} T \\beta m \\overline{\\xi(t)} + 4 K_{B} T m \\overline{\\xi(t)} \\overline{\\beta} + 4 K_{B} T m \\overline{\\xi(t)}\\right)}{4 \\sqrt{K_{B} T} \\sqrt{m} \\left(\\beta \\overline{\\beta} - 1\\right)}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\frac{\\sqrt{2} i \\lambda \\langle p \\rangle}{\\text{hbar}} + \\frac{\\sqrt{2} \\left(\\langle p \\rangle \\text{hbar} - i \\langle x \\rangle \\omega^{2} m^{2}\\right)}{2 m \\text{hbar}} + \\frac{\\sqrt{2} \\sqrt{\\lambda} \\left(- \\frac{\\xi(t) \\beta \\text{hbar}^{2}}{4} + \\frac{\\xi(t) \\text{hbar}^{2}}{4} - \\frac{\\beta \\overline{\\xi(t)} \\overline{\\beta} \\text{hbar}^{2}}{4} + \\frac{\\beta \\overline{\\xi(t)} \\text{hbar}^{2}}{4} - K_{B} T \\xi(t) \\beta m - K_{B} T \\xi(t) m - K_{B} T \\beta m \\overline{\\xi(t)} \\overline{\\beta} - K_{B} T \\beta m \\overline{\\xi(t)}\\right)}{\\sqrt{K_{B} T} \\sqrt{m} \\left(\\beta \\overline{\\beta} - 1\\right) \\text{hbar}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import sympy as sp\n",
    "\n",
    "from thesis_calculations.open_harmonic import (\n",
    "    get_closed_operator,\n",
    "    get_noise_operator,\n",
    "    get_open_operator,\n",
    "    noise,\n",
    ")\n",
    "from thesis_calculations.squeezed_states import (\n",
    "    alpha,\n",
    "    as_b_expr,\n",
    "    beta,\n",
    "    display_latex,\n",
    "    eval_groundstate,\n",
    "    get_alpha_derivative,\n",
    "    mu,\n",
    "    nu,\n",
    "    p_expr,\n",
    "    x_expr,\n",
    ")\n",
    "\n",
    "\n",
    "def _simplify_squeeze_params(expr: sp.Expr) -> sp.Expr:\n",
    "    expr = sp.simplify(expr)\n",
    "    expr = sp.simplify(expr.subs({nu: beta * mu}))\n",
    "    expr = expr.subs({mu**2: 1 / (1 - beta * sp.conjugate(beta))})\n",
    "    return sp.factor(sp.simplify(expr))\n",
    "\n",
    "\n",
    "print(\"Alpha Derivative\")  # noqa: T201\n",
    "open_operator = get_open_operator()\n",
    "open_derivative = get_alpha_derivative(get_open_operator())\n",
    "open_derivative = _simplify_squeeze_params(open_derivative)\n",
    "display_latex(open_derivative)\n",
    "\n",
    "\n",
    "closed_derivative = get_alpha_derivative(get_closed_operator())\n",
    "closed_derivative = _simplify_squeeze_params(closed_derivative)\n",
    "display_latex(closed_derivative)\n",
    "\n",
    "\n",
    "noise_derivative = get_alpha_derivative(get_noise_operator())\n",
    "noise_derivative = _simplify_squeeze_params(noise_derivative)\n",
    "display_latex(noise_derivative)\n",
    "\n",
    "derivative_alpha = open_derivative + closed_derivative + noise_derivative\n",
    "\n",
    "\n",
    "expect_x_expr = eval_groundstate(as_b_expr(x_expr))\n",
    "expect_p_expr = eval_groundstate(as_b_expr(p_expr))\n",
    "expect_x = sp.Symbol(r\"\\langle x \\rangle\", real=True)\n",
    "expect_p = sp.Symbol(r\"\\langle p \\rangle\", real=True)\n",
    "\n",
    "display_latex(expect_x_expr)\n",
    "display_latex(expect_p_expr)\n",
    "print(\n",
    "    sp.solve(\n",
    "        {\n",
    "            sp.Eq(expect_x, expect_x_expr),\n",
    "            sp.Eq(expect_p, expect_p_expr),\n",
    "        },\n",
    "        (alpha, sp.conjugate(alpha)),\n",
    "    )\n",
    ")\n",
    "\n",
    "\n",
    "def _alpha_expr_as_xp(expr: sp.Expr) -> sp.Expr:\n",
    "    solutions = sp.solve(\n",
    "        {\n",
    "            sp.Eq(expect_x, expect_x_expr),\n",
    "            sp.Eq(expect_p, expect_p_expr),\n",
    "        },\n",
    "        (alpha, sp.conjugate(alpha)),\n",
    "    )\n",
    "    expr = expr.subs(\n",
    "        {\n",
    "            alpha: solutions[alpha],\n",
    "            sp.conjugate(alpha): solutions[sp.conjugate(alpha)],\n",
    "        }\n",
    "    )\n",
    "    return sp.simplify(sp.expand(expr))\n",
    "\n",
    "\n",
    "derivative_as_xp = (\n",
    "    _alpha_expr_as_xp(open_derivative)\n",
    "    + _alpha_expr_as_xp(closed_derivative)\n",
    "    + _alpha_expr_as_xp(noise_derivative)\n",
    ")\n",
    "\n",
    "derivative_x = expect_x_expr.subs({alpha: derivative_as_xp})\n",
    "a, b = sp.expand(sp.simplify(derivative_x)).as_independent(noise)\n",
    "display_latex(sp.simplify(a) + sp.factor(sp.simplify(b)))\n",
    "\n",
    "\n",
    "derivative_p = expect_p_expr.subs({alpha: derivative_as_xp})\n",
    "a, b = sp.expand(sp.simplify(derivative_p)).as_independent(noise)\n",
    "display_latex(sp.simplify(a) + sp.factor(sp.simplify(b)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4b7c166-1af3-4fc5-89eb-89b50c4e2b93",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "92ab2eeb-d419-4f73-9ab8-cee2d85108ac",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

The pyproject.toml

[project]
name = "thesis_calculations"
version = "0.0.1"
description = "A collection of scripts for my thesis"
readme = "README.md"
requires-python = ">=3.14,<3.15"
dependencies = ["matplotlib>=3.10.6", "sympy>=1.14.0"]

[dependency-groups]
dev = [
    "ruff",
    "pytest >=8.3.3,<9.0.0",
    "sphinx >=8.1.3,<9.0.0",
    "pydata-sphinx-theme >=0.16.0,<0.17.0",
    "jupyter>=1.1.1",
    "ty>=0.0.1a21",
    "ipykernel>=6.30.1",
]


[tool.ruff]
unsafe-fixes = true
exclude = [".git", ".git-rewrite", ".vscode"]

[tool.ruff.lint]
select = ["ALL"]
preview = true
ignore = [
    "COM812",
    "E501",
    "S101",
    "PT009",
    "D100",
    "D105",
    "CPY001",
    "TD003",
    "TD002",
    "DOC201",
    "DOC402",
    "PD",
]
fixable = ["ALL"]
unfixable = ["T201"]


[tool.ruff.lint.extend-per-file-ignores]
"tests/**/*" = ["PLR6301", "INP001", "PLR0914", "D101", "D102", "D103", "D104"]
"scripts/**/*" = [
    "PLR6301",
    "INP001",
    "PLR0914",
    "D101",
    "D102",
    "D103",
    "D104",
]
"examples/**/*" = ["INP001", "T201"]
"docs/**/*" = ["INP001", "I002"]

[tool.ruff.lint.pylint]
allow-dunder-method-names = [
    "__as_fundamental__",
    "__from_fundamental__",
    "__into_fundamental__",
    "__as_transformed__",
    "__into_transformed__",
    "__from_transformed__",
    "__convert_vector_into__",
    "__into_inner__",
    "__from_inner__",
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"


[tool.pytest.ini_options]
testpaths = ["tests"]


[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

Version

ruff 0.14.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingnotebookRelated to (Jupyter) notebooks

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions