Commit Graph
151 Commits
Author SHA1 Message Date
David Landa-Marbán 2d327a6d32 Merge pull request #6424 from lechevaa/HybridNewton_flag
Hybrid newton flag
2025-10-06 09:51:37 +02:00
David Landa Marban 1fd280c68d Removing trailing spaces and adding eol at eof 2025-10-02 10:22:55 +02:00
lechevaa 5796d57604 Hybrid Newton Python tests and C++ refactoring 2025-09-29 10:59:55 +02:00
Arne Morten Kvarving 0afc5f352a Merge pull request #6482 from svenn-t/pysinglephase
Python one-phase (water) simulator
2025-09-23 15:24:02 +02:00
Arne Morten Kvarving 5efbb736aa Merge pull request #6492 from hakonhagland/docker_debugging
Improved python docker unit tests debugging
2025-09-23 13:24:12 +02:00
Svenn Tveit 8eaa56885d Use docstring template for OnePhaseSimulator documentation 2025-09-23 13:20:42 +02:00
Svenn Tveit 116e22e58c Safe creation of OnePhaseSimulator object in tests 2025-09-23 13:20:10 +02:00
Svenn Tveit 46559c532f Adressed review comments 2025-09-23 12:54:28 +02:00
Svenn Tveit fc3e1bb73f Tests for OnePhaseSimulator 2025-09-23 12:54:27 +02:00
Svenn Tveit 5153cd6fc0 Add OnePhaseSimulator to custom Python target 2025-09-23 12:52:46 +02:00
Svenn Tveit d0c08c4382 Python wrapper of single phase (water) simulator 2025-09-23 12:52:46 +02:00
Håkon Hægland bd402ee230 Fix auto-detection by not setting PYTHON_VERSIONS when not specified
The auto-detection wasn't working because the
CLI was always setting PYTHON_VERSIONS environment variable to all supported
versions when --python-versions was not provided.

Changes:
- click_helpers.py: Return None instead of all versions when option not provided
- helpers.py: Only set PYTHON_VERSIONS env var when explicitly specified
- main.py: Update type hints to allow None for python_versions parameter

Now the flow works correctly:
1. No --python-versions CLI option -> python_versions = None
2. None passed to Docker -> no PYTHON_VERSIONS env var set
3. Container auto-detects installed versions using pyenv
4. Tests run only on detected versions
2025-09-23 12:42:48 +02:00
Håkon Hægland 85344a3998 Auto-detect installed Python versions at runtime
When no --python-versions is specified at
runtime, auto-detect which Python versions are actually installed in the
container instead of defaulting to all versions from python_versions.json.

This resolves the issue where:
1. Building with --python-versions=3.12 installs only Python 3.12
2. Running without --python-versions would try to test all versions from JSON
3. Tests would fail for non-installed versions (3.8, 3.9, 3.10, 3.11, 3.13)

Now the runtime logic:
1. Uses `pyenv versions --bare` to detect installed versions
2. Maps full versions (3.12.9) to short versions (3.12)
3. Uses detected versions as default for testing
4. Falls back to JSON versions if detection fails

Example behavior:
- Build: --python-versions=3.12 (installs only 3.12.9)
- Runtime: auto-detects 3.12, tests only that version
- Explicit: --python-versions=3.11,3.12 still works as before
2025-09-23 11:46:27 +02:00
Håkon Hægland 412773785e Remove references to original behavior 2025-09-23 09:23:58 +02:00
Arne Morten Kvarving fafa4d8a19 Merge pull request #6418 from hakonhagland/docstring-template-refactor
Add support for Python docstring.json template format
2025-09-23 08:36:05 +02:00
Arne Morten Kvarving 7679d64ed1 Merge pull request #6488 from svenn-t/fix_pygaswater_tests
Fix Python gas-water simulator test failures
2025-09-23 08:31:49 +02:00
Håkon Hægland f355be1c65 Add debugging documentation for Docker wheel testing
Adds detailed documentation covering all debugging features implemented
in recent commits:

python/docker/test_wheels/scripts/README.md:
- New "Debugging" section with complete workflow examples
- Python version selection for faster builds (--python-versions)
- Focused test selection for isolation (--test-cases-common/simulators)
- Continue-on-error mode for comprehensive failure analysis
- Docker-specific debugging strategies
- Updated CLI option documentation

python/docker/README.md:
- Added debugging section reference with feature highlights
- Links to detailed debugging documentation
2025-09-23 08:31:34 +02:00
Håkon Hægland ac20e8ed87 Add --stop-on-error option for Docker wheel testing
Adds a new CLI option to control test execution behavior when failures occur:
- Without --stop-on-error (default): Continue running all tests even if some fail
- With --stop-on-error: Stop execution on first test failure (previous behavior)

This enables comprehensive debugging by running both opm-common and omp-simulators
tests in a single run, showing all failures at once rather than stopping at the first one.

Changes:
- Add --stop-on-error flag to run-docker-image command
- Pass STOP_ON_ERROR environment variable to Docker container
- Update entrypoint.py to handle continue-on-error behavior
- Modify test functions to check return codes and continue when appropriate
- Maintain backward compatibility with existing error handling
2025-09-23 08:13:53 +02:00
Håkon Hægland ddf2e3d338 Add Python version selection to Docker image builds
This enhancement allows specifying which Python versions to install during
Docker image builds, significantly reducing build times when only testing
specific Python versions during debugging.

Changes:
- Add --python-versions option to build-docker-image command
- Pass BUILD_PYTHON_VERSIONS build argument to Docker
- Update install_python_versions.py to respect BUILD_PYTHON_VERSIONS env var
- Validate requested versions against supported versions in python_versions.json
- Maintain backward compatibility (installs all versions if not specified)

Usage examples:
  # Build with only Python 3.12 (much faster for debugging)
  opm-wheels build-docker-image --docker-os="ubuntu-24.04" --python-versions="3.12"

  # Build with multiple specific versions
  omp-wheels build-docker-image --python-versions="3.11,3.12"

  # Build with all versions (original behavior)
  opm-wheels build-docker-image

Benefits:
- Reduces build time from ~7 minutes to ~2 minutes for single Python version
- Enables faster iteration during debugging of Docker-specific issues
- Particularly valuable when combined with --test-cases-* for focused testing
2025-09-23 07:06:24 +02:00
Håkon Hægland 0b8926c475 Add focused test selection for Docker wheel testing
This enhancement adds the ability to run specific test cases in the Docker
testing infrastructure, enabling more focused debugging and faster iteration
when investigating test failures.

Changes:
- Add --test-cases-common and --test-cases-simulators CLI options to opm-wheels
- Pass test selection as environment variables to Docker container
- Update entrypoint.py to support selective test execution:
  * Run only opm-common tests when --test-cases-common is specified
  * Run only opm-simulators tests when --test-cases-simulators is specified
  * Maintain backward compatibility (run all tests if no selection specified)
- Support both host-tests-dir and cloned repo testing modes

Usage examples:
  # Run only esmry tests from opm-common
  opm-wheels run-docker-image --test-cases-common=esmry

  # Run only basic tests from opm-simulators
  opm-wheels run-docker-image --test-cases-simulators=basic

  # Run specific tests from both suites
  opm-wheels run-docker-image --test-cases-common=esmry --test-cases-simulators=mpi

This enables efficient debugging of Docker-specific test failures by isolating
problematic test cases without running the full test suite.
2025-09-23 06:48:20 +02:00
Håkon Hægland c195df978d Refactor: Use factory fixtures for simulator creation in tests
Move simulator instantiation to factory functions that automatically
disable async ECL output. This prevents future contributors from
forgetting the --enable-async-ecl-output=false flag.

- Add create_black_oil_simulator/create_gas_water_simulator to pytest_common
- Define ENABLE_ASYNC_ECL_OUTPUT_FLAG constant
- Update all tests to use factory functions
- No functional changes, pure refactoring
2025-09-23 05:09:20 +02:00
Håkon Hægland 831354a0db Fix race condition in Python tests by disabling async ECL output
Add --enable-async-ecl-output=false to all Python simulator tests to prevent
race condition between async file writing tasklets and pushd context manager.

Problem:
- Tests use pushd() to change directory before running simulations
- Simulator dispatches async tasklets to write ECL output files
- pushd context exits before async writes complete
- Tasklets write files in wrong directory (build/python/ instead of test_data/)
- Causes confusing error messages and misplaced output files

Solution:
- Disable async ECL output during tests for deterministic behavior
- Files now created in correct locations within test_data/ directories
- Eliminates "Can not open EclFile" errors in logs
- Makes test execution predictable and synchronous
2025-09-22 20:46:10 +02:00
Svenn Tveit b79d16c3e8 Fix failures in docker tests 2025-09-19 14:18:22 +02:00
David Landa Marban d3101a9c80 BIOFILM effects for gas-water systems 2025-09-18 11:15:48 +02:00
Håkon Hægland 2f6bf952e1 Use new docstring format for python modules 2025-09-17 15:35:17 +02:00
Arne Morten Kvarving 26660b6640 python packaging: update to use python_simulator_modules target 2025-09-17 14:53:52 +02:00
Håkon Hægland 7552aec2c0 Update CMakeLists.txt to pass simulator type to docstring generator
- Add 'BlackOil' as 5th parameter to generate_docstring_hpp.py
- Prepares for template-based docstring generation
- Will work with updated opm-common generate_docstring_hpp.py script
2025-09-17 14:47:04 +02:00
Håkon Hægland 6fe5742145 Convert docstrings to template format with simulator configurations
- Create unified template structure with 'simulators', 'constructors', and 'common_methods' sections
- Add support for both BlackOil and GasWater simulators
- Use {{name}} and {{class}} placeholders for template expansion
- Eliminates need for duplicate JSON files
2025-09-17 14:47:02 +02:00
Håkon Hægland 3c6313b619 Custom target to build all simulator modules
Create a convenience target to build all Python simulator modules.
2025-09-17 10:06:50 +02:00
Svenn Tveit 753fcc2ec4 Cleaned up formatting 2025-09-17 10:06:50 +02:00
Svenn Tveit a69e10485b Clarify ordering and clean up doc in rest of the tests 2025-09-17 10:06:50 +02:00
Håkon Hægland b5e7ccc0b1 Clarify why test case ordering is necessary
and delete comment in code about static variables that can no longer be
reproduced.
2025-09-17 10:06:49 +02:00
Svenn Tveit 67a701ef4f Tests for PyGasWaterSimulator 2025-09-17 10:06:49 +02:00
Svenn Tveit 32dd09c78f Add Python gas-water simulator and refactor to template base class
Extend the Python blackoil simulator to support two-phase gas-water
simulations by extracting common functionality into a template base
class and implementing proper module separation.

- Extract PyBaseSimulator<TypeTag> template base class containing all
  common simulator functionality (20+ methods including advance, run,
  step, property access, and MPI handling)
- Add PyGasWaterSimulator for two-phase gas-water simulations using
  FlowGasWaterProblem TypeTag with oil phase disabled
- Split Python modules to avoid ODR violations:
  - BlackOil.so for PyBlackOilSimulator (FlowProblemTPFA)
  - GasWater.so for PyGasWaterSimulator (FlowGasWaterProblem)
- Implement proper template instantiation control with explicit
  instantiations per module

- Eliminate ~400 lines of code duplication between simulators
- Clean inheritance hierarchy: derived classes contain only constructors
- Type-safe specialization through OPM's TypeTag property system
- Separate docstring generation for each simulator type
- Independent build targets with shared infrastructure

- Update CMakeLists.txt to support multiple pybind11 modules
- Add docstrings_gw_simulators.json for gas-water simulator documentation
- Remove centralized Pybind11Exporter.cpp in favor of distributed exports
- Implement proper build dependencies and custom targets

This establishes a scalable foundation for extending OPM's Python
bindings to support additional simulator types (thermal, polymer,
solvent) while maintaining type safety and avoiding symbol conflicts.

Files changed: 21 files, 915 insertions, 428 deletions
2025-09-17 10:06:44 +02:00
Arne Morten Kvarving b44692349e python packaging: enable LTO 2025-09-15 09:53:25 +02:00
Håkon Hægland 53270c95b6 docker: clean pip usage and drop pytest-runner
- Export PIP_ROOT_USER_ACTION=ignore to silence root-user warning in manylinux.
- Remove pytest-runner from build-time pip installs; no longer needed after
  removing setup_requires.
2025-09-12 17:57:33 +02:00
Håkon Hægland ac490531f1 python/docker: finalize pyproject build-system and SPDX license
- Bump setuptools floor to >=61 in pyproject.toml with rationale comments.
- Declare build-backend explicitly; keep classic scikit-build.
- Switch setup.py license to SPDX expression (GPL-3.0-or-later) and remove
  deprecated license classifier, keeping only non-license classifiers.
2025-09-12 16:06:51 +02:00
Håkon Hægland 31716f2cef docker/python: switch to PEP 517 builds via python -m build
- Replace direct setup.py invocations with: python -m build --sdist --wheel
- Add comments explaining motivation (setuptools deprecations, build isolation)
  and why we drop explicit --plat-name/--python-tag (auditwheel/env handles).
- Ensure the build frontend is present per-interpreter by installing 'build'.

Also add build-backend to pyproject.toml with notes and TODO for full modernization.
2025-09-12 16:00:57 +02:00
Håkon Hægland ce3ee6fc98 python: remove deprecated setup.py args (setuptools warnings)
- Drop legacy setup_requires and test_suite to stop
  setuptools _DeprecatedInstaller / fetch_build_eggs and
  unknown distribution option warnings.
- Add inline comment explaining rationale and PEP 517 context.
2025-09-12 15:42:24 +02:00
Håkon Hægland d5664a5f1c python/docker(test_wheels): prefer hyphenated OS names; accept colon input
- Default --docker-os to ubuntu-22.04
- Normalize input (: -> -) for paths/tags
- Fallback to legacy directories pre-rename
- Update docs with Windows compatibility note
2025-09-12 13:08:40 +02:00
Håkon Hægland bd69d21af8 docker(test_wheels): rename dockerfiles dirs to hyphen (Windows checkout fix)
- debian:11    -> debian-11
- ubuntu:22.04 -> ubuntu-22.04
- ubuntu:24.04 -> ubuntu-24.04

CLI accepts colon or hyphen; code now canonicalizes to hyphen.
2025-09-12 13:06:41 +02:00
Håkon Hægland 922e0c0522 Copy host dir files to container to avoid conflict.
Copy host directory files from opm-simulators/python and
opm-common/python to container to avoid conflict with
opm-simulators/python/opm/ and opm-common/python/opm/ folders when
running "python -m unittest discover" from the python directories.
An alternative would be to rename the opm directories in the host.
2025-09-04 17:15:11 +02:00
Håkon Hægland 9167a35ae4 Add option to use opm python tests folders from host
This will help avoid rebuilding the test containers each time
the host data changes.
2025-09-04 13:25:57 +02:00
Håkon Hægland ec56668d8b Fix path lookup for python_versions.json file 2025-09-04 11:58:17 +02:00
Håkon Hægland 4bc25047c2 Trim white space at EOL 2025-09-04 11:24:05 +02:00
lechevaa b7595cce3a Hybrid Newton flag small fix + change from boost to PropertyTree 2025-09-01 15:54:23 +02:00
lechevaa 6dfcb6f856 Hybrid Newton small fixes + first test commit 2025-09-01 15:54:23 +02:00
Håkon Hægland be8039a0a8 Add support for version_tag
Add support for adding a version tag to the generated wheels
2025-08-28 11:37:56 +02:00
Håkon Hægland 158ddddca0 Replace head with merge
Don't encourage building PR branches directly
2025-08-28 11:25:25 +02:00
Håkon Hægland 6e2503cac8 Major Python Docker Build System Restructure and Enhancement
Reorganize Python folder: separate Docker/PyPI from CMake/PyBind11 workflows
and implement comprehensive build automation

This commit represents a comprehensive restructuring and enhancement of the
OPM Python build system, addressing maintainability, consistency, and
usability issues through architectural improvements and automation.

FILES CHANGED
=============

Refactored:
- python/Dockerfile -> python/docker/Dockerfile
- python/generate-pypi-package.sh -> python/docker/scripts/generate-pypi-package.sh
- python/setup-docker-image.sh -> python/docker/scripts/setup-docker-image.sh
- python/build-deps.sh -> python/docker/scripts/build-boost.sh
- python/build-deps.sh -> python/docker/scripts/build-dune.sh

Added (24 files):
- python/docker/python_versions.json (single source of truth)
- python/docker/scripts/sync_versions.sh
- python/docker/scripts/read_python_config.py
- python/docker/run-docker-build.sh
- python/docker/README.md
- python/docker/test_wheels/* (complete testing framework)

Modified:
- python/setup.py.in
- .gitignore

MAJOR CHANGES
=============

Architecture Restructure
------------------------
- Separated build workflows: Clearly distinguished Docker/PyPI wheel
  generation from CMake/PyBind11 compilation
- Moved Docker-specific files: Relocated docker build system to
  appropriate locations
- Streamlined organization: Created logical separation between different
  build contexts

Single Source of Truth Configuration
-------------------------------------
- Centralized Python version management: Created python_versions.json as
  authoritative configuration
- Automated synchronization: Built sync_versions.sh script to maintain
  consistency across all components
- Dynamic configuration: Components now read from JSON rather than
  hardcoded values

Enhanced Docker Build System
----------------------------
- Multi-OS support: Added Ubuntu 22.04, Ubuntu 24.04, and Debian 11
  Dockerfiles
- Improved caching: Split dependencies into separate Docker layers for
  better build performance
- Fixed PyPI wheel generation: Added LD_LIBRARY_PATH setup for proper
  library bundling, corrected auditwheel wheel copying from wheelhouse/
  instead of dist/
- Optimized Docker layer structure: Delayed source code copying until
  final stage, preventing dependency rebuilds on source changes and
  reducing iteration time from 30+ to <5 minutes during development

Build Automation & Tooling
--------------------------
- Comprehensive wheel testing: Created opm-wheels CLI tool for building
  and testing Docker images
- Automated validation: Integrated Python version validation and error
  handling
- Enhanced scripts: Improved generate-pypi-package.sh with better error
  handling and version management

Testing Framework
-----------------
- Docker-based testing: Complete framework for testing wheels across
  multiple Python versions and OS configurations
- Automated validation: Wheel installation and import testing with
  comprehensive error reporting
- Multi-version support: Parallel testing across Python 3.8-3.13
- Platform verification: Validates manylinux wheels install and function
  correctly across Ubuntu 22.04/24.04 and Debian 11

Documentation & Usability
-------------------------
- Comprehensive maintenance guides: Detailed instructions for
  adding/removing Python versions
- Clear workflows: Step-by-step procedures for build system maintenance
- Improved CLI experience: Better error messages, path handling, and
  user guidance
- Updated documentation: Enhanced README files with practical examples
  and troubleshooting

IMPACT
======

This restructure transforms the Python build system from a collection of
loosely coupled scripts into a cohesive, maintainable, and reliable build
automation system. The single source of truth configuration eliminates the
primary source of maintenance overhead, while the enhanced testing
framework provides confidence in the quality of generated wheels.

The changes enable the OPM project to more easily support new Python
versions, maintain consistency across platforms, and provide a better
developer experience for both maintainers and users.
2025-08-28 07:24:46 +02:00