Skip to content

Commit

Permalink
Rename: userdata and ensemble_ids endpoints
Browse files Browse the repository at this point in the history
- Rename ensembles into ensemble_ids
- Change prior endpoint
- Bump up ert-storage==0.2.0
- Use userdata instead of metadata in extraction
- Change ert-storage==0.2.0 version in dev-requirements
  • Loading branch information
xjules committed Jun 18, 2021
1 parent 9550634 commit 09ff647
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
black
ert-storage==0.1.7
ert-storage==0.2.0
flaky
pytest>=6.2.0
pytest-qt
Expand Down
14 changes: 7 additions & 7 deletions ert3/storage/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _get_experiment_by_name(experiment_name: str) -> Dict[str, Any]:

def init(*, workspace: Path) -> None:
response = _get_from_server(path="experiments")
experiment_names = {exp["name"]: exp["ensembles"] for exp in response.json()}
experiment_names = {exp["name"]: exp["ensemble_ids"] for exp in response.json()}

for special_key in _SPECIAL_KEYS:
if f"{workspace}.{special_key}" in experiment_names:
Expand Down Expand Up @@ -219,7 +219,7 @@ def _add_numerical_data(
record_type=_get_record_type(ensemble_record),
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
record_url = f"ensembles/{ensemble_id}/records/{record_name}"

for idx, record in enumerate(ensemble_record.records):
Expand All @@ -238,7 +238,7 @@ def _add_numerical_data(
raise ert3.exceptions.StorageError(response.text)

meta_response = _put_to_server(
path=f"{record_url}/metadata",
path=f"{record_url}/userdata",
params={"realization_index": idx},
json=metadata.dict(),
)
Expand Down Expand Up @@ -282,7 +282,7 @@ def _response2record(

def _get_numerical_metadata(ensemble_id: str, record_name: str) -> _NumericalMetaData:
response = _get_from_server(
path=f"ensembles/{ensemble_id}/records/{record_name}/metadata",
path=f"ensembles/{ensemble_id}/records/{record_name}/userdata",
params={"realization_index": 0}, # This assumes there is a realization 0
)

Expand All @@ -306,7 +306,7 @@ def _get_numerical_data(
f"Cannot get {record_name} data, no experiment named: {experiment_name}"
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
metadata = _get_numerical_metadata(ensemble_id, record_name)

records = []
Expand Down Expand Up @@ -371,7 +371,7 @@ def get_ensemble_record_names(
f"Cannot get record names of non-existing experiment: {experiment_name}"
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
response = _get_from_server(path=f"ensembles/{ensemble_id}/records")
if response.status_code != 200:
raise ert3.exceptions.StorageError(response.text)
Expand All @@ -388,7 +388,7 @@ def get_experiment_parameters(
f"Cannot get parameters from non-existing experiment: {experiment_name}"
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
response = _get_from_server(path=f"ensembles/{ensemble_id}/parameters")
if response.status_code != 200:
raise ert3.exceptions.StorageError(response.text)
Expand Down
2 changes: 1 addition & 1 deletion ert_shared/storage/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_ensemble(
parameter_names=parameter_names,
response_names=response_names,
update_id=update_id,
metadata={"name": ert.get_current_case_name()},
userdata={"name": ert.get_current_case_name()},
)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def package_files(directory):
],
extras_require={
"storage": [
"ert-storage==0.1.8",
"ert-storage==0.2.0",
],
},
setup_requires=["pytest-runner", "setuptools_scm"],
Expand Down
8 changes: 4 additions & 4 deletions tests/storage/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ def test_empty_ensemble(client):
# Name is "default"
for ens in client.get(f"/experiments/{id}/ensembles").json():
assert (
client.get(f"/ensembles/{ens['id']}/metadata").json()["name"] == "default"
client.get(f"/ensembles/{ens['id']}/userdata").json()["name"] == "default"
)

# No priors exist
assert client.get(f"/experiments/{id}/priors").json() == {}
assert client.get(f"/experiments/{id}").json()["priors"] == {}


def test_empty_ensemble_with_name(client):
Expand All @@ -189,7 +189,7 @@ def test_empty_ensemble_with_name(client):
# Compare results
id = client.fetch_experiment()
for ens in client.get(f"/experiments/{id}/ensembles").json():
assert client.get(f"/ensembles/{ens['id']}/metadata").json()["name"] == name
assert client.get(f"/ensembles/{ens['id']}/userdata").json()["name"] == name


def test_priors(client):
Expand All @@ -209,7 +209,7 @@ def test_priors(client):

# Compare results
id = client.fetch_experiment()
actual_priors = client.get(f"/experiments/{id}/priors").json()
actual_priors = client.get(f"/experiments/{id}").json()["priors"]
assert len(priors) == len(actual_priors)
for name, _, resp in priors:
assert actual_priors[f"COEFFS:{name}"] == resp
Expand Down

0 comments on commit 09ff647

Please sign in to comment.