Skip to content

Commit 7dadd3b

Browse files
committed
Merge branch 'master' into hybrid_search
2 parents ecc7f30 + 2472f85 commit 7dadd3b

38 files changed

+1714
-1366
lines changed

.github/workflows/testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ jobs:
6666
env:
6767
GITHUB_TOKEN: ${{ secrets.PAT }}
6868
steps:
69-
- uses: rymndhng/release-on-push-action@v0.25.0
69+
- uses: rymndhng/release-on-push-action@v0.28.0
7070
with:
7171
bump_version_scheme: norelease

mpcontribs-api/Dockerfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM materialsproject/devops:python-3.1110.3 AS base
1+
FROM materialsproject/devops:python-3.1110.8 AS base
22
RUN apt-get update && apt-get install -y --no-install-recommends supervisor libopenblas-dev libpq-dev vim && apt-get clean
33
WORKDIR /app
44

@@ -12,11 +12,13 @@ COPY mpcontribs mpcontribs
1212
RUN pip install $PIP_FLAGS --no-deps .
1313
#ENV SETUPTOOLS_SCM_PRETEND_VERSION 0.0.0
1414
#COPY marshmallow-mongoengine marshmallow-mongoengine
15-
#RUN cd marshmallow-mongoengine && pip install $PIP_FLAGS --no-deps .
15+
#RUN cd marshmallow-mongoengine && pip install $PIP_FLAGS --no-deps -e .
1616
#COPY mimerender mimerender
17-
#RUN cd mimerender && pip install $PIP_FLAGS --no-deps .
17+
#RUN cd mimerender && pip install $PIP_FLAGS --no-deps -e .
1818
#COPY flask-mongorest flask-mongorest
19-
#RUN cd flask-mongorest && pip install $PIP_FLAGS --no-deps .
19+
#RUN cd flask-mongorest && pip install $PIP_FLAGS --no-deps -e .
20+
#COPY AtlasQ AtlasQ
21+
#RUN cd AtlasQ && pip install $PIP_FLAGS --no-deps -e .
2022
RUN wget -q https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && \
2123
chmod +x wait-for-it.sh && mv wait-for-it.sh /usr/local/bin/ && \
2224
wget -q https://github.com/materialsproject/MPContribs/blob/master/mpcontribs-api/mpcontribs/api/contributions/formulae.json.gz?raw=true \

mpcontribs-api/mpcontribs/api/contributions/document.py

+27-21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from hashlib import md5
66
from math import isnan
7+
from bson.dbref import DBRef
78
from datetime import datetime
89
from flask import current_app
910
from atlasq import AtlasManager, AtlasQ
@@ -18,8 +19,6 @@
1819
from boltons.iterutils import remap
1920
from decimal import Decimal
2021
from pint import UnitRegistry
21-
from pint.unit import UnitDefinition
22-
from pint.converters import ScaleConverter
2322
from pint.errors import DimensionalityError
2423
from uncertainties import ufloat_fromstr
2524
from pymatgen.core import Composition, Element
@@ -35,12 +34,18 @@
3534
lambda s: s.replace("%", " percent "),
3635
],
3736
)
38-
ureg.default_format = "~,P"
39-
40-
ureg.define(UnitDefinition("percent", "%", (), ScaleConverter(0.01)))
41-
ureg.define(UnitDefinition("permille", "%%", (), ScaleConverter(0.001)))
42-
ureg.define(UnitDefinition("ppm", "ppm", (), ScaleConverter(1e-6)))
43-
ureg.define(UnitDefinition("ppb", "ppb", (), ScaleConverter(1e-9)))
37+
ureg.formatter.default_format = "~,P"
38+
39+
if "percent" not in ureg:
40+
# percent is native in pint >= 0.21
41+
ureg.define("percent = 0.01 = %")
42+
if "permille" not in ureg:
43+
# permille is native in pint >= 0.24.2
44+
ureg.define("permille = 0.001 = ‰ = %%")
45+
if "ppm" not in ureg:
46+
# ppm is native in pint >= 0.21
47+
ureg.define("ppm = 1e-6")
48+
ureg.define("ppb = 1e-9")
4449
ureg.define("atom = 1")
4550
ureg.define("bohr_magneton = e * hbar / (2 * m_e) = µᵇ = µ_B = mu_B")
4651
ureg.define("electron_mass = 9.1093837015e-31 kg = mₑ = m_e")
@@ -68,12 +73,12 @@ def format_cell(cell):
6873
return cell
6974

7075
q = get_quantity(cell)
71-
if not q or isnan(q.nominal_value):
76+
if not q or isnan(q.magnitude.nominal_value):
7277
return cell
7378

7479
q = truncate_digits(q)
7580
try:
76-
return str(q.nominal_value) if isnan(q.std_dev) else str(q)
81+
return str(q.magnitude.nominal_value) if isnan(q.magnitude.std_dev) else str(q)
7782
except Exception:
7883
return cell
7984

@@ -102,10 +107,10 @@ def get_quantity(s):
102107

103108

104109
def truncate_digits(q):
105-
if isnan(q.nominal_value):
110+
if isnan(q.magnitude.nominal_value):
106111
return q
107112

108-
v = Decimal(str(q.nominal_value))
113+
v = Decimal(str(q.magnitude.nominal_value))
109114
vt = v.as_tuple()
110115

111116
if vt.exponent >= 0:
@@ -114,8 +119,8 @@ def truncate_digits(q):
114119
dgts = len(vt.digits)
115120
dgts = max_dgts if dgts > max_dgts else dgts
116121
s = f"{v:.{dgts}g}"
117-
if not isnan(q.std_dev):
118-
s += f"+/-{q.std_dev:.{dgts}g}"
122+
if not isnan(q.magnitude.std_dev):
123+
s += f"+/-{q.magnitude.std_dev:.{dgts}g}"
119124

120125
if q.units:
121126
s += f" {q.units}"
@@ -260,7 +265,7 @@ def make_quantities(path, key, value):
260265
return key, value
261266

262267
# silently ignore "nan"
263-
if isnan(q.nominal_value):
268+
if isnan(q.magnitude.nominal_value):
264269
return False
265270

266271
# ensure that the same units are used across contributions
@@ -288,11 +293,11 @@ def make_quantities(path, key, value):
288293
q = truncate_digits(q)
289294

290295
# return new value dict
291-
display = str(q.value) if isnan(q.std_dev) else str(q)
296+
display = str(q.value) if isnan(q.magnitude.std_dev) else str(q)
292297
value = {
293298
"display": display,
294-
"value": q.nominal_value,
295-
"error": q.std_dev,
299+
"value": q.magnitude.nominal_value,
300+
"error": q.magnitude.std_dev,
296301
"unit": str(q.units),
297302
}
298303
return key, value
@@ -307,10 +312,11 @@ def pre_delete(cls, sender, document, **kwargs):
307312
document.reload(*args)
308313

309314
for component in COMPONENTS.keys():
310-
# check if other contributions exist before deletion!
311-
for idx, obj in enumerate(getattr(document, component)):
315+
# check if other contributions exist before deletion
316+
# and make sure component still exists (getattr converts ref to object)
317+
for obj in getattr(document, component):
312318
q = {component: obj.id}
313-
if sender.objects(**q).count() < 2:
319+
if sender.objects(**q).count() < 2 and not isinstance(obj, DBRef):
314320
obj.delete()
315321

316322

mpcontribs-api/mpcontribs/api/contributions/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def has_add_permission(self, req, obj):
165165
raise Unauthorized(f"Can't add {obj.identifier}: {msg}")
166166

167167
query = dict(project=obj.project.id, identifier=obj.identifier)
168-
if obj.project.unique_identifiers and Contributions.objects(query).count():
168+
if obj.project.unique_identifiers and Contributions.objects(**query).count():
169169
raise Unauthorized(f"{obj.identifier} already added for {obj.project.id}")
170170

171171
return True

mpcontribs-api/mpcontribs/api/projects/document.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -274,29 +274,29 @@ def post_save(cls, sender, document, **kwargs):
274274

275275
# resolve/lookup component fields
276276
# NOTE also includes dynamic document fields
277-
for component in COMPONENTS.keys():
278-
pipeline.append(
279-
{
280-
"$lookup": {
281-
"from": component,
282-
"localField": component,
283-
"foreignField": "_id",
284-
"as": component,
285-
}
286-
}
287-
)
277+
# for component in COMPONENTS.keys():
278+
# pipeline.append(
279+
# {
280+
# "$lookup": {
281+
# "from": component,
282+
# "localField": component,
283+
# "foreignField": "_id",
284+
# "as": component,
285+
# }
286+
# }
287+
# )
288288

289289
# document size and attachment content size
290290
project_stage = {
291-
"_id": 0,
292-
"size": {"$bsonSize": "$$ROOT"},
293-
"contents": {
294-
"$map": { # attachment sizes
295-
"input": "$attachments",
296-
"as": "attm",
297-
"in": {"$toInt": "$$attm.content"},
298-
}
299-
},
291+
# "_id": 0,
292+
# "size": {"$bsonSize": "$$ROOT"},
293+
# "contents": {
294+
# "$map": { # attachment sizes
295+
# "input": "$attachments",
296+
# "as": "attm",
297+
# "in": {"$toInt": "$$attm.content"},
298+
# }
299+
# },
300300
}
301301

302302
# number of components
@@ -321,14 +321,14 @@ def post_save(cls, sender, document, **kwargs):
321321
pipeline.append({"$project": project_stage})
322322

323323
# forward fields and sum attachment contents
324-
project_stage_2 = {k: 1 for k, v in project_stage.items()}
325-
project_stage_2["contents"] = {"$sum": "$contents"}
324+
project_stage_2 = {k: 1 for k in project_stage.keys()}
325+
# project_stage_2["contents"] = {"$sum": "$contents"}
326326
pipeline.append({"$project": project_stage_2})
327327

328328
# total size and total number of components
329329
group_stage = {
330330
"_id": None,
331-
"size": {"$sum": {"$add": ["$size", "$contents"]}},
331+
# "size": {"$sum": {"$add": ["$size", "$contents"]}},
332332
}
333333
for component in COMPONENTS.keys():
334334
group_stage[component] = {"$sum": f"${component}"}
@@ -357,7 +357,7 @@ def post_save(cls, sender, document, **kwargs):
357357
# prep and save stats
358358
stats_kwargs = {"columns": len(columns), "contributions": ncontribs}
359359
if result and result[0]:
360-
stats_kwargs["size"] = result[0]["size"] / 1024 / 1024
360+
# stats_kwargs["size"] = result[0]["size"] / 1024 / 1024
361361
for component in COMPONENTS.keys():
362362
stats_kwargs[component] = result[0].get(component, 0)
363363
if stats_kwargs[component] > 0:

0 commit comments

Comments
 (0)