Skip to content

Commit

Permalink
Replace ecl with resdata
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Nov 13, 2023
1 parent 1fbcf37 commit 42f3ee1
Show file tree
Hide file tree
Showing 44 changed files with 342 additions and 338 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/annotate_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies from PyPI
run: |
python3 -m pip install "conan<2" pybind11 ecl
python3 -m pip install "conan<2" pybind11 resdata
- name: Create compile commands for clib
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Install dependencies from PyPI
run: |
python3 -m pip install "conan<2" pybind11 ecl
python3 -m pip install "conan<2" pybind11 resdata
echo "PIP_PKGS_PATH=$(python3 -m pip show conan | grep Location | cut -d ' ' -f 2 | sed -e 's@/lib/.*site-packages$@/bin@')" >> "$GITHUB_ENV"
- name: Build ert clib
Expand Down
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ignore_errors = True
[mypy-cwrap.*]
ignore_missing_imports = True

[mypy-ecl.*]
[mypy-resdata.*]
ignore_missing_imports = True

[mypy-resfo.*]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $ ert --help

The `ert` program is based on two different repositories:

1. [ecl](https://github.com/Equinor/ecl) which contains utilities to read and write Eclipse files.
1. [resdata](https://github.com/Equinor/resdata) which contains utilities to read and write Eclipse files.

2. ert - this repository - the actual application and all of the GUI.

Expand Down Expand Up @@ -223,16 +223,16 @@ command `ulimit -a`. In order to increase maximum number of open files, run

### Running C++ tests

The C++ code and tests require [libecl](https://github.com/Equinor/ecl). As long
as you have `pip install ecl`'d into your Python virtualenv all should work.
The C++ code and tests require [resdata](https://github.com/Equinor/resdata). As long
as you have `pip install resdata`'d into your Python virtualenv all should work.

``` sh
# Create and enable a virtualenv
python3 -m venv my_virtualenv
source my_virtualenv/bin/activate

# Install build dependencies
pip install pybind11 conan cmake ecl
pip install pybind11 conan cmake resdata

# Build ERT and tests
mkdir build && cd build
Expand Down
2 changes: 1 addition & 1 deletion ci/run_ert_ctests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enable_environment () {

setup () {
/opt/rh/rh-python38/root/usr/bin/python -m venv ${ERT_SOURCE_ROOT}/venv
${ERT_SOURCE_ROOT}/venv/bin/pip install -U pip wheel setuptools cmake pybind11 "conan<2" ecl
${ERT_SOURCE_ROOT}/venv/bin/pip install -U pip wheel setuptools cmake pybind11 "conan<2" resdata
}

build_ert_clib () {
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = [
"scikit-build",
"cmake",
"ninja",
"ecl",
"resdata",
"conan<2",
"pybind11>=2.10.0", # If this comes out of sync with the version installed by Conan please update the version in CMakeLists
]
Expand Down Expand Up @@ -46,7 +46,7 @@ dependencies=[
"cwrap",
"deprecation",
"dnspython >= 2",
"ecl >= 2.14.1",
"resdata",
"ert-storage >= 0.3.16",
"fastapi < 0.100.0",
"filelock",
Expand Down
8 changes: 4 additions & 4 deletions script/ecl-check
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_symbols(path: str, *, undefined: bool) -> Set[str]:
def parse_args() -> argparse.Namespace:
ap = argparse.ArgumentParser(
description="""\
Script that finds symbols used by libres that are implemented in libecl.
Script that finds symbols used by libres that are implemented in redsata.
"""
)
ap.add_argument(
Expand All @@ -76,13 +76,13 @@ def parse_args() -> argparse.Namespace:
def main() -> None:
args = parse_args()

import ecl
import resdata

from ert.job_queue import ResPrototype

res_syms = get_symbols(ResPrototype.lib._name, undefined=True)
ecl_syms = get_symbols(ecl.EclPrototype.lib._name, undefined=False)
shared_syms = ecl_syms & res_syms
resdata_syms = get_symbols(resdata.ResdataPrototype.lib._name, undefined=False)
shared_syms = resdata_syms & res_syms

sym_count = {}
total = 0
Expand Down
13 changes: 7 additions & 6 deletions src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,26 @@ execute_process(
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")

# -----------------------------------------------------------------
# Detect libecl
# Detect resdata
# -----------------------------------------------------------------

execute_process(
COMMAND "${_python_executable}" -c "import ecl; print(ecl.get_include())"
COMMAND "${_python_executable}" -c
"import resdata; print(resdata.get_include())"
OUTPUT_VARIABLE ECL_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL
LAST)

execute_process(
COMMAND "${_python_executable}" -c
"import ecl; print(ecl.EclPrototype.lib._name)"
"import resdata; print(resdata.ResdataPrototype.lib._name)"
OUTPUT_VARIABLE ECL_LIBRARY
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL
LAST)

add_library(ecl SHARED IMPORTED GLOBAL)
set_target_properties(ecl PROPERTIES IMPORTED_LOCATION "${ECL_LIBRARY}"
IMPORTED_NO_SONAME TRUE)
add_library(resdata SHARED IMPORTED GLOBAL)
set_target_properties(resdata PROPERTIES IMPORTED_LOCATION "${ECL_LIBRARY}"
IMPORTED_NO_SONAME TRUE)

function(fix_install_names target)
# CMake doesn't let us link to absolute paths on macOS. This means that
Expand Down
2 changes: 1 addition & 1 deletion src/clib/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ file(

if(BUILD_TESTS)
add_library(ert SHARED $<TARGET_OBJECTS:_clib>)
target_link_libraries(ert _clib pybind11::embed ecl)
target_link_libraries(ert _clib pybind11::embed resdata)
fix_install_names(ert)
endif()
14 changes: 7 additions & 7 deletions src/clib/lib/enkf/enkf_obs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
#include <map>
#include <utility>

#include <ert/ecl/ecl_sum.h>
#include <ert/python.hpp>
#include <ert/res_util/string.hpp>
#include <resdata/rd_sum.h>

ERT_CLIB_SUBMODULE("enkf_obs", m) {
using namespace py::literals;
m.def("read_from_refcase",
[](Cwrap<ecl_sum_type> refcase, std::string local_key) {
int num_steps = ecl_sum_get_last_report_step(refcase);
[](Cwrap<rd_sum_type> refcase, std::string local_key) {
int num_steps = rd_sum_get_last_report_step(refcase);
std::vector<bool> valid(num_steps + 1);
std::vector<double> value(num_steps + 1);
for (int tstep = 0; tstep <= num_steps; tstep++) {
if (ecl_sum_has_report_step(refcase, tstep)) {
int time_index = ecl_sum_iget_report_end(refcase, tstep);
value[tstep] = ecl_sum_get_general_var(
refcase, time_index, local_key.c_str());
if (rd_sum_has_report_step(refcase, tstep)) {
int time_index = rd_sum_iget_report_end(refcase, tstep);
value[tstep] = rd_sum_get_general_var(refcase, time_index,
local_key.c_str());
valid[tstep] = true;
} else {
valid[tstep] = false;
Expand Down
71 changes: 35 additions & 36 deletions src/clib/lib/enkf/read_summary.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <algorithm>
#include <ert/ecl/ecl_smspec.hpp>
#include <ert/ecl/ecl_sum.hpp>
#include <ert/python.hpp>
#include <fnmatch.h>
#include <pybind11/pybind11.h>
#include <resdata/rd_smspec.hpp>
#include <resdata/rd_sum.hpp>
#include <stdexcept>
#include <string>
#include <time.h>
Expand All @@ -20,11 +20,11 @@ static bool matches(const std::vector<std::string> &patterns, const char *key) {
}

ERT_CLIB_SUBMODULE("_read_summary", m) {
m.def("read_dates", [](Cwrap<ecl_sum_type> summary) {
m.def("read_dates", [](Cwrap<rd_sum_type> summary) {
if (!PyDateTimeAPI)
PyDateTime_IMPORT;

time_t_vector_type *tvec = ecl_sum_alloc_time_vector(summary, true);
time_t_vector_type *tvec = rd_sum_alloc_time_vector(summary, true);
int size = time_t_vector_size(tvec);
pybind11::list result(size);
auto t = tm{};
Expand Down Expand Up @@ -52,36 +52,35 @@ ERT_CLIB_SUBMODULE("_read_summary", m) {
time_t_vector_free(tvec);
return result;
});
m.def("read_summary",
[](Cwrap<ecl_sum_type> summary, std::vector<std::string> keys) {
const ecl_smspec_type *smspec = ecl_sum_get_smspec(summary);
std::vector<std::pair<std::string, std::vector<double>>>
summary_vectors{};
std::vector<std::string> seen_keys{};
for (int i = 0; i < ecl_smspec_num_nodes(smspec); i++) {
const ecl::smspec_node &smspec_node =
ecl_smspec_iget_node_w_node_index(smspec, i);
const char *key = smspec_node.get_gen_key1();
if ((matches(keys, key)) &&
!(std::find(seen_keys.begin(), seen_keys.end(), key) !=
seen_keys.end())) {
seen_keys.push_back(key);
int start = ecl_sum_get_first_report_step(summary);
int end = ecl_sum_get_last_report_step(summary);
std::vector<double> data{};
int key_index =
ecl_sum_get_general_var_params_index(summary, key);
for (int tstep = start; tstep <= end; tstep++) {
if (ecl_sum_has_report_step(summary, tstep)) {
int time_index =
ecl_sum_iget_report_end(summary, tstep);
data.push_back(
ecl_sum_iget(summary, time_index, key_index));
}
}
summary_vectors.emplace_back(key, data);
}
}
return summary_vectors;
});
m.def("read_summary", [](Cwrap<rd_sum_type> summary,
std::vector<std::string> keys) {
const rd_smspec_type *smspec = rd_sum_get_smspec(summary);
std::vector<std::pair<std::string, std::vector<double>>>
summary_vectors{};
std::vector<std::string> seen_keys{};
for (int i = 0; i < rd_smspec_num_nodes(smspec); i++) {
const rd::smspec_node &smspec_node =
rd_smspec_iget_node_w_node_index(smspec, i);
const char *key = smspec_node.get_gen_key1();
if ((matches(keys, key)) &&
!(std::find(seen_keys.begin(), seen_keys.end(), key) !=
seen_keys.end())) {
seen_keys.push_back(key);
int start = rd_sum_get_first_report_step(summary);
int end = rd_sum_get_last_report_step(summary);
std::vector<double> data{};
int key_index =
rd_sum_get_general_var_params_index(summary, key);
for (int tstep = start; tstep <= end; tstep++) {
if (rd_sum_has_report_step(summary, tstep)) {
int time_index = rd_sum_iget_report_end(summary, tstep);
data.push_back(
rd_sum_iget(summary, time_index, key_index));
}
}
summary_vectors.emplace_back(key, data);
}
}
return summary_vectors;
});
}
2 changes: 1 addition & 1 deletion src/ert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from uuid import UUID

import yaml
from ecl import set_abort_handler
from resdata import set_abort_handler

import ert.shared
from ert.cli import (
Expand Down
8 changes: 4 additions & 4 deletions src/ert/config/ensemble_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Type, Union, no_type_check, overload

from ecl.summary import EclSum
from resdata.summary import Summary

from ert.field_utils import get_shape

Expand Down Expand Up @@ -41,7 +41,7 @@ def _get_abs_path(file: Optional[str]) -> Optional[str]:

class EnsembleConfig:
@staticmethod
def _load_refcase(refcase_file: Optional[str]) -> Optional[EclSum]:
def _load_refcase(refcase_file: Optional[str]) -> Optional[Summary]:
if refcase_file is None:
return None

Expand All @@ -67,7 +67,7 @@ def _load_refcase(refcase_file: Optional[str]) -> Optional[EclSum]:
"lazy_load": False,
"file_options": 0,
}
return EclSum(**refcase_load_args)
return Summary(**refcase_load_args)

def __init__(
self,
Expand All @@ -77,7 +77,7 @@ def __init__(
surface_list: Optional[List[SurfaceConfig]] = None,
summary_config: Optional[SummaryConfig] = None,
field_list: Optional[List[Field]] = None,
refcase: Optional[EclSum] = None,
refcase: Optional[Summary] = None,
) -> None:
_genkw_list = [] if genkw_list is None else genkw_list
_gendata_list = [] if gendata_list is None else gendata_list
Expand Down
2 changes: 1 addition & 1 deletion src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)

import xarray as xr
from ecl.util.util import CTime
from resdata.util.util import CTime
from typing_extensions import Self

from ert.substitution_list import SubstitutionList
Expand Down
10 changes: 5 additions & 5 deletions src/ert/config/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import numpy as np
import xarray as xr
from ecl.summary import EclSumVarType
from ecl.util.util import IntVector
from resdata.summary import SummaryVarType
from resdata.util.util import IntVector

from ert._clib.enkf_obs import read_from_refcase

Expand Down Expand Up @@ -114,12 +114,12 @@ def _handle_history_observation(
var_type = refcase.var_type(summary_key)
local_key = None
if var_type in [
EclSumVarType.ECL_SMSPEC_WELL_VAR,
EclSumVarType.ECL_SMSPEC_GROUP_VAR,
SummaryVarType.RD_SMSPEC_WELL_VAR,
SummaryVarType.RD_SMSPEC_GROUP_VAR,
]:
summary_node = refcase.smspec_node(summary_key)
local_key = summary_node.keyword + "H:" + summary_node.wgname
elif var_type == EclSumVarType.ECL_SMSPEC_FIELD_VAR:
elif var_type == SummaryVarType.RD_SMSPEC_FIELD_VAR:
summary_node = refcase.smspec_node(summary_key)
local_key = summary_node.keyword + "H"
else:
Expand Down
4 changes: 2 additions & 2 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import TYPE_CHECKING, Set, Union

import xarray as xr
from ecl.summary import EclSum
from resdata.summary import Summary

from ert._clib._read_summary import ( # pylint: disable=import-error
read_dates,
Expand Down Expand Up @@ -35,7 +35,7 @@ def __post_init__(self) -> None:
def read_from_file(self, run_path: str, iens: int) -> xr.Dataset:
filename = self.input_file.replace("<IENS>", str(iens))
try:
summary = EclSum(
summary = Summary(
f"{run_path}/{filename}",
include_restart=False,
lazy_load=False,
Expand Down
6 changes: 4 additions & 2 deletions src/ert/gui/about_dialog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ecl
import resdata
from qtpy.QtCore import QSize, Qt
from qtpy.QtGui import QFont
from qtpy.QtWidgets import QDialog, QHBoxLayout, QLabel, QPushButton, QVBoxLayout
Expand Down Expand Up @@ -52,7 +52,9 @@ def createInfoLayout():
version = QLabel()

version.setAlignment(Qt.AlignHCenter)
version.setText(f"Versions: ecl:{ecl.__version__} ert:{ert_gui.__version__}")
version.setText(
f"Versions: resdata:{resdata.__version__} ert:{ert_gui.__version__}"
)
info_layout.addWidget(version)

info_layout.addStretch(5)
Expand Down
Loading

0 comments on commit 42f3ee1

Please sign in to comment.