Skip to content
Open
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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ classifiers = [
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = ["array-api-compat>=1.12", "numpy>=2.0,<3", "opt_einsum>=3.4.0"]
dependencies = ["array-api-compat>=1.12", "numpy>=2.0,<3", "opt_einsum>=3.4.0", "psutil"]


[project.optional-dependencies]
Expand Down
9 changes: 8 additions & 1 deletion src/src_method/utils/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
synchronous no-ops, so the same algorithm code runs on both backends.
"""

from __future__ import annotations

import os
from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING, Any, TypeAlias

import numpy as np
from array_api_compat import numpy as np_compat

import psutil

Check failure on line 22 in src/src_method/utils/_backend.py

View workflow job for this annotation

GitHub Actions / lint

ruff (I001)

src/src_method/utils/_backend.py:12:1: I001 Import block is un-sorted or un-formatted help: Organize imports

if TYPE_CHECKING:
from collections.abc import Iterator, Sequence
from types import ModuleType
Expand Down Expand Up @@ -378,10 +380,15 @@
for line in path.read_text().splitlines():
if line.startswith("MemAvailable:"):
return int(line.split()[1]) * 1024
return os.sysconf("SC_AVPHYS_PAGES") * os.sysconf("SC_PAGE_SIZE")

try:
return os.sysconf("SC_AVPHYS_PAGES") * os.sysconf("SC_PAGE_SIZE")
except (ValueError, OSError):
return psutil.virtual_memory().available



def sketch_dtype(dtype: DTypeLike | None, *inputs: Sequence[Site]) -> np.dtype:

Check failure on line 391 in src/src_method/utils/_backend.py

View workflow job for this annotation

GitHub Actions / lint

ruff (unformatted)

src/src_method/utils/_backend.py:390:1: unformatted: File would be reformatted
"""Resolve the sketch dtype.

Args:
Expand Down
Loading