Skip to content

Conversation

@mimakaev
Copy link
Collaborator

@mimakaev mimakaev commented Oct 26, 2025

Description

This PR contains fixes for the python 3.14 switching from fork to forkserver multiprocessing method, addresses some deprecation warnings, and reformats things with black.

  • Changed CI to include 3.14 and two latest versions of MacOS
  • black and isort on the codebase
  • Switched contactmaps to be compatible with spawn and forkserver multiprocessing (latest default in 3.14)
  • removed confusing test for an old starting conformation generator
  • Addressed all flake8 issues and some valid VSCode warnings such as possibly unbound variables

PR Checklist

  • [] apply "black" to the whole codebase (black .)
  • [] apply isort to the codebase (isort .)
  • [] fun flake8 and try to resolve all the issues (work in progress!)

@mimakaev mimakaev requested a review from Copilot November 11, 2025 16:56
Copilot finished reviewing on behalf of mimakaev November 11, 2025 16:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the polychrom codebase for Python 3.14 compatibility, focusing on multiprocessing method changes (fork → forkserver), addressing deprecation warnings, and applying code formatting with black/isort.

Key Changes:

  • Updated CI/CD to test against Python 3.14 and recent macOS versions
  • Refactored contactmaps module for spawn/forkserver multiprocessing compatibility (lambda functions → named functions)
  • Fixed NumPy deprecation (np.in1dnp.isin) and improved type checking patterns
  • Applied consistent code formatting across the codebase

Reviewed Changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
.github/workflows/pythonapp.yml Added Python 3.14 and macOS testing matrix
polychrom/contactmaps.py Refactored for multiprocessing compatibility: moved lambdas to module-level functions, added default function parameters
tests/test_contactmaps.py Replaced lambda with named load_function for spawn/forkserver compatibility; added module-level test data
polychrom/forces.py Updated cylindrical_confinement logic and type hints; contains a bug with bottom=0 handling
polychrom/forcekits.py Added explicit error for unsupported nonbonded forces (potential breaking change)
tests/test_polymer_analyses.py Fixed NumPy deprecation: np.in1dnp.isin
tests/test_io.py Updated to use new load_URI API instead of deprecated fetch_block
polychrom/polymer_analyses.py Added TYPE_CHECKING pattern for better Cython import handling
polychrom/param_units.py Reformatted docstrings with black (r""" prefix)
polychrom/hdf5_format.py Changed type() to isinstance() for better practices
polychrom/legacy/forces.py Reordered imports and changed to isinstance()
Various files Import reordering (isort), spacing fixes, removed extra blank lines (black formatting)
tests/test_configurations.py Removed entire test file for old starting conformation generator
Examples Import reordering and formatting improvements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

bottom = 0 if bottom is True else bottom

if bottom is not None:
if bottom:
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic change here introduces a bug. When bottom=0 is passed, the condition if bottom: (line 734) will evaluate to False because 0 is falsy in Python, causing the code to use the wrong branch.

The original code correctly used if bottom is not None: which would handle bottom=0 properly. The fix should be:

bottom = 0 if bottom is True else bottom

if bottom is not None:
    # ... existing code for bottom confinement
Suggested change
if bottom:
if bottom is not None:

Copilot uses AI. Check for mistakes.
Comment on lines +130 to +131
else:
raise ValueError("Nonbonded force {} does not support exceptions or exclusions.".format(nb_force.name))
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters the behavior when except_bonds=True and the nonbonded force doesn't support exceptions or exclusions. Previously, the code would silently continue without adding exceptions. Now it raises a ValueError.

While this is likely an improvement (making the error explicit rather than silent), it could break existing code that relies on the previous behavior. Consider documenting this breaking change or verifying that all nonbonded forces in use support either exceptions or exclusions.

Copilot uses AI. Check for mistakes.
@@ -1 +1 @@
from polychrom.polymerutils import * # noqa: F403
from polychrom.polymerutils import * # noqa: F403
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import pollutes the enclosing namespace, as the imported module polychrom.polymerutils does not define 'all'.

Suggested change
from polychrom.polymerutils import * # noqa: F403
# TODO: Replace the following line with explicit imports of only the required names.
# For example: from polychrom.polymerutils import foo, bar
# from polychrom.polymerutils import * # noqa: F403

Copilot uses AI. Check for mistakes.
from mirnylib.numutils import zoomArray
from openmmlib import polymerutils

import matplotlib
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'matplotlib' is not used.

Suggested change
import matplotlib

Copilot uses AI. Check for mistakes.
from mirnylib.numutils import completeIC, coarsegrain
from mirnylib.h5dict import h5dict
from mirnylib.numutils import coarsegrain, completeIC, zoomArray
from mirnylib.plotting import nicePlot
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'nicePlot' is not used.

Suggested change
from mirnylib.plotting import nicePlot

Copilot uses AI. Check for mistakes.
import warnings
from collections.abc import Iterable
from typing import Optional, Dict
from typing import Dict, Optional
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Dict' is not used.
Import of 'Optional' is not used.

Suggested change
from typing import Dict, Optional

Copilot uses AI. Check for mistakes.
@mimakaev
Copy link
Collaborator Author

unused imports and other things will be addressed in a next PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants