Skip to content

Commit

Permalink
Merge pull request #96 from precice/python-bindings-v2.2.0.2
Browse files Browse the repository at this point in the history
Release v2.2.0.2
  • Loading branch information
IshaanDesai authored Apr 7, 2021
2 parents d5383d6 + 73998fa commit 7eeadef
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 91 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Update build environment

on:
workflow_dispatch: # Trigger by hand from the UI
schedule:
- cron: '0 0 * * 0' # Schedule it every Sunday

jobs:
build-spack-pyprecice-deps:
name: Builds the baseimage for spack providing dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- name: Login to registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
context: .
file: spack/ci-spack-pyprecice-deps-1804.dockerfile
tags: precice/ci-spack-pyprecice-deps-1804
29 changes: 7 additions & 22 deletions .github/workflows/build-spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,18 @@ jobs:
build_spack:
name: build_spack
runs-on: ubuntu-latest
timeout-minutes: 5
container: benjaminrueth/ci-spack-pyprecice-deps-1804
timeout-minutes: 15
container: precice/ci-spack-pyprecice-deps-1804
defaults:
run:
shell: "bash --login -eo pipefail {0}"
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install pip3
- name: Move Package Script
run: |
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
- name: Install jinja2
run: pip3 install --user jinja2
- name: Extract branch name # from https://stackoverflow.com/a/58035262/5158031
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Specify Package Script
cp spack/repo/packages/py-pyprecice/package.py /py-pyprecice-repo/packages/py-pyprecice/
cp spack/repo/packages/py-pyprecice/*.patch /py-pyprecice-repo/packages/py-pyprecice/
- name: Try to build py-pyprecice with spack and test it
run: |
python3 spack/jinja-instantiate.py --branch ${{ steps.extract_branch.outputs.branch }} > /opt/spack/var/spack/repos/builtin/packages/py-pyprecice/package.py
ls spack/var/spack/repos/builtin/packages/py-pyprecice
cp spack/var/spack/repos/builtin/packages/py-pyprecice/*.patch /opt/spack/var/spack/repos/builtin/packages/py-pyprecice/
ls spack/var/spack/repos/builtin/packages/py-pyprecice
- name: Try to build py-pyprecice with spack
run: |
. /opt/spack/share/spack/setup-env.sh && spack env activate precice && spack add py-pyprecice@develop ^precice@develop && spack concretize -f && spack install -v
- name: Import precice and print version
run: |
. /opt/spack/share/spack/setup-env.sh && spack env activate precice && python3 -c "import precice; print(precice.__version__)"
. /opt/spack/share/spack/setup-env.sh && spack env activate ci && spack arch && spack find && spack dev-build py-pyprecice@develop target=x86_64 && spack load precice py-numpy py-mpi4py py-cython openssh openmpi && mkdir runner && cd runner && python3 -c "import precice; print(precice.__version__)"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## 2.2.0.2

* Improved error messgaes for all assertions. https://github.com/precice/python-bindings/pull/9
* Improve CI w.r.t spack package. https://github.com/precice/python-bindings/pull/89

## 2.2.0.1

* Format complete codebase according to PEP8 and test formatting. https://github.com/precice/python-bindings/pull/82
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Python language bindings for the C++ library preCICE

This package provides python language bindings for the C++ library [preCICE](https://github.com/precice/precice). Note that the first three digits of the version number of the bindings indicate the preCICE version that the bindings support. The last digit represents the version of the bindings. Example: `v2.0.0.1` and `v2.0.0.2` of the bindings represent versions `1` and `2` of the bindings that are compatible with preCICE `v2.0.0`.

# User documentation

Please refer to [precice.org](https://www.precice.org/installation-bindings-python.html) for information on how to install and use the python bindings. Information below is intended for advanced users and developers.

# Required dependencies

**preCICE**: Refer to [the preCICE wiki](https://github.com/precice/precice/wiki#1-get-precice) for information on building and installation.
Expand All @@ -20,7 +24,7 @@ This package provides python language bindings for the C++ library [preCICE](htt
We recommend using pip3 (version 19.0.0 or newer required) for the sake of simplicity. You can check your pip3 version via `pip3 --version`. To update pip3, use the following line:

```
$ pip3 install --upgrade pip
$ pip3 install --user --upgrade pip
```

## Using pip3
Expand Down Expand Up @@ -264,6 +268,20 @@ python setup.py install --user
```
</details>

### ValueError while importing preCICE
If you face the error:

```bash
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
```

make sure that you are using an up-to-date version of NumPy. You can update NumPy with

```bash
pip3 install numpy --upgrade
```


# Contributors

* [Benjamin Rüth](https://github.com/BenjaminRueth)
Expand Down
25 changes: 13 additions & 12 deletions cyprecice/cyprecice.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ cdef class Interface:

if len(position) > 0:
dimensions = len(position)
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of vertex coordinate in set_mesh_vertex does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
elif len(position) == 0:
dimensions = self.get_dimensions()

Expand Down Expand Up @@ -530,7 +530,7 @@ cdef class Interface:

if len(positions) > 0:
size, dimensions = positions.shape
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of vertex coordinates in set_mesh_vertices does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
elif len(positions) == 0:
size = positions.shape[0]
dimensions = self.get_dimensions()
Expand Down Expand Up @@ -640,7 +640,7 @@ cdef class Interface:

if len(positions) > 0:
size, dimensions = positions.shape
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of position coordinates in get_mesh_vertex_ids_from_positions does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
elif len(positions) == 0:
size = positions.shape[0]
dimensions = self.get_dimensions()
Expand Down Expand Up @@ -892,15 +892,15 @@ cdef class Interface:

if len(values) > 0:
size, dimensions = values.shape
assert(dimensions == self.get_dimensions())
assert dimensions == self.get_dimensions(), "Dimensions of vector data in write_block_vector_data does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())
if len(values) == 0:
size = 0

cdef np.ndarray[int, ndim=1] _vertex_ids = np.ascontiguousarray(vertex_ids, dtype=np.int32)
cdef np.ndarray[double, ndim=1] _values = np.ascontiguousarray(values.flatten(), dtype=np.double)

assert(_values.size == size * self.get_dimensions())
assert(_vertex_ids.size == size)
assert _values.size == size * self.get_dimensions(), "Vector data is not provided for all vertices in write_block_vector_data. Check length of input data provided. Provided size: {}, expected size: {}".format(_values.size, size * self.get_dimensions())
assert _vertex_ids.size == size, "Vertex IDs are of incorrect length in write_block_vector_data. Check length of vertex ids input. Provided size: {}, expected size: {}".format(_vertex_ids.size, size)

self.thisptr.writeBlockVectorData (data_id, size, <const int*>_vertex_ids.data, <const double*>_values.data)

Expand Down Expand Up @@ -941,11 +941,14 @@ cdef class Interface:
>>> interface.write_vector_data(data_id, vertex_id, value)
"""
check_array_like(value, "value", "write_vector_data")
assert len(value) > 0, "Input vector data is empty in write_vector_data"

assert(len(value) > 0)
dimensions = len(value)
assert(dimensions == self.get_dimensions())

assert dimensions == self.get_dimensions(), "Dimensions of vector data in write_vector_data does not match with dimensions in problem definition. Provided dimensions: {}, expected dimensions: {}".format(dimensions, self.get_dimensions())

cdef np.ndarray[np.double_t, ndim=1] _value = np.ascontiguousarray(value, dtype=np.double)

self.thisptr.writeVectorData (data_id, vertex_id, <const double*>_value.data)

def write_block_scalar_data (self, data_id, vertex_ids, values):
Expand Down Expand Up @@ -985,13 +988,11 @@ cdef class Interface:
if len(values) == 0:
size = 0


cdef np.ndarray[int, ndim=1] _vertex_ids = np.ascontiguousarray(vertex_ids, dtype=np.int32)
cdef np.ndarray[double, ndim=1] _values = np.ascontiguousarray(values, dtype=np.double)

assert(_values.size == size)
assert(_vertex_ids.size == size)

assert _values.size == size, "Scalar data is not provided for all vertices in write_block_scalar_data. Check size of input data provided. Provided size: {}, expected size: {}".format(_values.size, size)
assert _vertex_ids.size == size, "Vertex IDs are of incorrect length in write_block_scalar_data. Check size of vertex ids input. Provided size: {}, expected size: {}".format(_vertex_ids.size, size)
self.thisptr.writeBlockScalarData (data_id, size, <const int*>_vertex_ids.data, <const double*>_values.data)

def write_scalar_data (self, data_id, vertex_id, double value):
Expand Down
12 changes: 6 additions & 6 deletions docs/ReleaseGuide.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
## Guide to release new version of python-bindings
The developer who is releasing a new version of the python-bindings is expected to follow this work flow:

The release of the `python-bindings` repository is made directly from a release branch called `release_v2.1.1.1`. This branch is mainly needed to help other developers with testing.
The release of the `python-bindings` repository is made directly from a release branch called `python-bindings-v2.1.1.1`. This branch is mainly needed to help other developers with testing.

1. Create a branch called `release_v2.1.1.1` from the latest commit of the `develop` branch.
1. Create a branch called `python-bindings-v2.1.1.1` from the latest commit of the `develop` branch.

2. [Open a Pull Request `master` <-- `release_v2.1.1.1`](https://github.com/precice/python-bindings/compare/master...master) named after the version (i.e. `Release v2.1.1.1`) and briefly describe the new features of the release in the PR description.
2. [Open a Pull Request `master` <-- `python-bindings-v2.1.1.1`](https://github.com/precice/python-bindings/compare/master...master) named after the version (i.e. `Release v2.1.1.1`) and briefly describe the new features of the release in the PR description.

3. Bump the version in the following places:

* `CHANGELOG.md` on `release v2.1.1.1`.
* `CHANGELOG.md` on `python-bindings-v2.1.1.1`.
* There is no need to bump the version anywhere else, since we use the [python-versioneer](https://github.com/python-versioneer/python-versioneer/) for maintaining the version everywhere else.

4. [Draft a New Release](https://github.com/precice/python-bindings/releases/new) in the `Releases` section of the repository page in a web browser. The release tag needs to be the exact version number (i.e.`v2.1.1.1` or `v2.1.1.1rc1`, compare to [existing tags](https://github.com/precice/python-bindings/tags)). Use `@target:master`. Release title is also the version number (i.e. `v2.1.1.1` or `v2.1.1.1rc1`, compare to [existing releases](https://github.com/precice/python-bindings/tags)).

* *Note:* We use the [python-versioneer](https://github.com/python-versioneer/python-versioneer/) for maintaining the version. Therefore the tag directly defines the version in all relevant places.
* *Note:* If it is a pre-release then the option *This is a pre-release* needs to be selected at the bottom of the page. Use `@target:release_v2.1.1.1` for a pre-release, since we will never merge a pre-release into master.
* *Note:* If it is a pre-release then the option *This is a pre-release* needs to be selected at the bottom of the page. Use `@target:python-bindings-v2.1.1.1` for a pre-release, since we will never merge a pre-release into master.

a) If a pre-release is made: Directly hit the "Publish release" button in your Release Draft. Now you can check the artifacts (e.g. release on [PyPI](https://pypi.org/project/pyprecice/#history)) of the release. *Note:* As soon as a new tag is created github actions will take care of deploying the new version on PyPI using [this workflow](https://github.com/precice/python-bindings/actions?query=workflow%3A%22Upload+Python+Package%22).

b) If this is a "real" release: As soon as one approving review is made, merge the release PR (from `release_v2.1.1.1`) into `master`.
b) If this is a "real" release: As soon as one approving review is made, merge the release PR (from `python-bindings-v2.1.1.1`) into `master`.

6. Merge `master` into `develop` for synchronization of `develop`.

Expand Down
9 changes: 9 additions & 0 deletions precice/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
__version__ = "unknown"

import warnings
from cyprecice import Interface, action_read_iteration_checkpoint, action_write_iteration_checkpoint, action_write_initial_data, get_version_information


def SolverInterface(*args):
"""
This is just a dummy function to avoid wrong usage of the interface. Please use precice.Interface, if you want to establish a connection to preCICE. See https://github.com/precice/python-bindings/issues/92 for more information.
"""
warnings.warn("please use precice.Interface to create the interface to C++ preCICE. Note that this function (precice.SolverInterface) does not do anything but throwing this warning. See https://github.com/precice/python-bindings/issues/92 for more information.")


from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
2 changes: 1 addition & 1 deletion solverdummy/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyprecice==2.0
pyprecice>=2.0
argparse>=1.4
numpy>=1.16
19 changes: 6 additions & 13 deletions spack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

The Spack package `py-pyprecice` provides the python bindings via Spack and was submitted via https://github.com/spack/spack/pull/19558. This folder contains the Spack package script that can be used for testing whether the Spack installation works.

Note that the file `var/spack/repos/builtin/packages/py-pyprecice/package.py` is a template that can be specified using `jinja2`. Run `python3 jinja-instrantiate.py` to do so. You may use the `--branch` argument to specify a branch. Example:
```
python3 jinja-instantiate --branch feature > my_package_script.py
```
## Docker image `precice/ci-spack-pyprecice-deps-1804`

## Docker image ci-spack-pyprecice-deps-1804
The workflow `build_env` in `.github/workflows/build-spack.yml` creates the image `precice/ci-spack-pyprecice-deps-1804`. This image contains all dependencies of `py-pyprecice@develop`.

The workflow `build_spack` in `.github/workflows/build-spack.yml` uses the image `precice/ci-spack-pyprecice-deps-1804` to reduce build time. The workflow uses the `package.py` from this repository to build the latest version of the bindings and run a small test on this version.

The test `build_spack` in `.github/workflows/build-spack.yml` uses the image `benjaminrueth/ci-spack-pyprecice-deps-1804` to reduce build time. Use the file `ci-spack-pyprecice-deps-1804.dockerfile` from this folder for building this image:
```
docker build -f ci-spack-pyprecice-deps-1804.dockerfile -t USERNAME/ci-spack-pyprecice-deps-1804.dockerfile .
docker push USERNAME/ci-spack-pyprecice-deps-1804.dockerfile
```
## When a new spack release is necessary

* Add checksum of newest version(s) to https://github.com/precice/python-bindings/blob/develop/spack/var/spack/repos/builtin/packages/py-pyprecice/package.py. You can get checksum for any released version by running `spack checksum py-pyprecice`.
* Run `python3 jinja-instantiate > package.py` to generate the latest version of `package.py`.
* Use `package.py` together with the patches provided in `python-bindings/spack/var/spack/repos/builtin/packages/py-pyprecice` to [create a pull request for Spack](https://github.com/spack/spack/compare) and submit the new release.
* Add checksum of newest version(s) to https://github.com/precice/python-bindings/blob/develop/spack/repo/packages/py-pyprecice/package.py. You can get checksum for any released version by running `spack checksum py-pyprecice`.
* Use `package.py` together with the patches provided in `python-bindings/spack/repo/packages/py-pyprecice` to [create a pull request for Spack](https://github.com/spack/spack/compare) and submit the new release.
17 changes: 10 additions & 7 deletions spack/ci-spack-pyprecice-deps-1804.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Build stage with Spack pre-installed and ready to be used
FROM spack/ubuntu-bionic:latest
RUN spack env create precice
# Install dependencies for precice and py-pyprecice
RUN spack env activate precice \
&& spack add [email protected] [email protected] [email protected] openssh [email protected] pkgconfig precice@develop py-setuptools py-wheel py-cython py-numpy py-mpi4py \
&& spack concretize -f \
&& spack install
FROM spack/ubuntu-bionic:latest

# Mount the current sources into the build container
# and build the default environment
ADD ./spack/repo /py-pyprecice-repo
RUN spack --color=always env create --without-view ci && \
spack --color=always -e ci add py-pyprecice@develop target=x86_64 && \
spack --color=always -e ci repo add /py-pyprecice-repo && \
spack --color=always -e ci install --fail-fast --only=dependencies && \
spack --color=always clean -a
15 changes: 0 additions & 15 deletions spack/jinja-instantiate.py

This file was deleted.

Loading

0 comments on commit 7eeadef

Please sign in to comment.