Skip to content

Conversation

@PythonFZ
Copy link
Collaborator

@PythonFZ PythonFZ commented Oct 15, 2025

This PR introduces mlipx serve CLI tools for automatically serving MLIPs in dedicated environments.

  • tests
  • uvx support
  • how to handle custom projects
  • check for models.py in current directory as default!

PythonFZ and others added 7 commits October 15, 2025 12:09
This commit enhances the ZeroMQ-based serve infrastructure with several
operational improvements and a new status monitoring command:

**Reliability Improvements:**
- Fix worker identity collision by adding hostname and random suffix
- Add IPC socket cleanup on broker shutdown and startup
- Add broker socket existence check before worker connection
- Implement worker shutdown detection when broker disconnects

**New Features:**
- Add `mlipx serve-status` command with rich formatted output
- Add `get_broker_status()` function for programmatic status checks

**Benefits:**
- Prevents "address already in use" errors from stale socket files
- Provides clear error messages when broker is not running
- Workers gracefully exit when broker stops instead of hanging
- Easy troubleshooting with new status command

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@PythonFZ PythonFZ requested a review from Copilot October 15, 2025 20:01
Copy link

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 introduces a comprehensive ZeroMQ-based model serving infrastructure to mlipx, enabling remote execution of MLIP calculations with automatic dependency management and load balancing. The system provides transparent integration with existing mlipx code through environment variables and API extensions.

Key changes:

  • Implements a broker-worker architecture using ZeroMQ for MLIP model serving
  • Adds automatic dependency management via UV extras for model isolation
  • Integrates serving capabilities directly into GenericASECalculator with fallback behavior

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pyproject.toml Adds pyzmq and msgpack dependencies for ZeroMQ communication
mlipx/serve/worker.py Implements worker processes that serve MLIP calculations via ZeroMQ
mlipx/serve/protocol.py Provides protocol utilities for ZeroMQ communication with msgpack serialization
mlipx/serve/client.py Client interface for connecting to MLIP servers via ZeroMQ broker
mlipx/serve/broker.py Broker process for load balancing MLIP workers using LRU pattern
mlipx/serve/autostart_broker.py Broker with automatic worker starting capabilities
mlipx/serve/init.py Module initialization exposing serve API components
mlipx/recipes/models.py.jinja2 Updates model definitions to include serve integration with extra dependencies
mlipx/nodes/generic_ase.py Extends GenericASECalculator to support remote serving via get_calculator method
mlipx/cli/main.py Adds CLI commands for serve-broker, serve, and serve-status
docs/source/concept/serve.rst Documentation for the serve infrastructure
docs/source/concept/models.rst Documentation updates for serve integration
docs/source/concept.rst Adds serve to documentation index

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 286 to 287
namespace = {"mlipx": mlipx}
exec(rendered_code, namespace)
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

Using exec() with user-provided models file content poses a security risk. Consider implementing a safer approach using importlib or ast parsing, or at minimum add validation/sanitization of the input.

Copilot uses AI. Check for mistakes.
PythonFZ and others added 13 commits November 26, 2025 14:28
- Move pyzmq/msgpack to optional [serve] extra dependency
- Add import guard with helpful error message for missing deps
- Rename name -> serve_name for consistency across model classes
  (OrbCalc, MatglModel, FairchemModel, GenericASECalculator)
- Add username to socket paths for user isolation on shared systems
- Add cross-platform broker locking using flufl.lock
- Fix race condition in autostart broker by processing frontend
  messages during worker startup wait loop
- Add stderr capture for auto-started workers to log files
- Improve CLI error styling with Rich console
- Add comprehensive integration tests (14 new tests)
- Update documentation with new features and troubleshooting guide

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment on lines 503 to 504
# Prevent infinite recursion
os.environ["_MLIPX_SERVE_UV_WRAPPED"] = "1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is that?

console.print(f"[dim]Command: {' '.join(cmd)}[/dim]")

os.execvp(cmd[0], cmd) # Replace current process
return # Never reached
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

??

@PythonFZ PythonFZ mentioned this pull request Dec 4, 2025
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