Skip to content

Commit 1f44eea

Browse files
committed
Fixed version conflict when merging main
2 parents afdc533 + 70382a9 commit 1f44eea

File tree

11 files changed

+120
-76
lines changed

11 files changed

+120
-76
lines changed

src/citrine/_rest/collection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import warnings
21
from abc import abstractmethod
32
from logging import getLogger
43
from typing import Optional, Union, Generic, TypeVar, Iterable, Iterator
@@ -137,5 +136,5 @@ def _build_collection_elements(self,
137136
except(KeyError, ValueError) as e:
138137
# TODO(PLA-9109): This is a patch to handle deprecated predictors client side
139138
# Remove when predictors are migrated
140-
warnings.warn(f"Building element skipped due to error: {e}", UserWarning)
139+
logger.warning(f"Building element skipped due to error: {e}")
141140
pass

src/citrine/builders/auto_configure.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from logging import getLogger
12
from uuid import UUID
23
from typing import Union, Optional, List
3-
import warnings
44

55
from gemd.entity.link_by_uid import LinkByUID
66
from gemd.enumeration.base_enumeration import BaseEnumeration
@@ -24,6 +24,8 @@
2424

2525
from citrine.builders.scores import create_default_score
2626

27+
logger = getLogger(__name__)
28+
2729

2830
class AutoConfigureStatus(BaseEnumeration):
2931
"""[ALPHA] The current status of the AutoConfigureWorkflow.
@@ -135,7 +137,7 @@ def __init__(self, *, project: Project, name: str):
135137

136138
@staticmethod
137139
def _print_status(msg: str):
138-
print(f"AutoConfigureWorkflow: {msg}")
140+
logger.info(f"AutoConfigureWorkflow: {msg}")
139141

140142
@property
141143
def project(self) -> Project:
@@ -229,17 +231,17 @@ def _update_assets(self):
229231
)
230232
else:
231233
self._table_config = self.project.table_configs.get(self.table_config.uid)
232-
print("Found existing: {}".format(self.table_config))
234+
logger.info("Found existing: {}".format(self.table_config))
233235

234236
# Table
235237
if self.table is None:
236238
if self.table_config is not None:
237239
self._table = next(self.project.tables.list_by_config(self.table_config.uid), None)
238240
if self.table is not None:
239-
print("Found existing: {}".format(self.table))
241+
logger.info("Found existing: {}".format(self.table))
240242
else:
241243
self._table = self.project.tables.get(self.table.uid)
242-
print("Found existing: {}".format(self.table))
244+
logger.info("Found existing: {}".format(self.table))
243245

244246
# Predictor
245247
if self.predictor is None:
@@ -249,7 +251,7 @@ def _update_assets(self):
249251
)
250252
else:
251253
self._predictor = self.project.predictors.get(self.predictor.uid)
252-
print("Found existing: {}".format(self.predictor))
254+
logger.info("Found existing: {}".format(self.predictor))
253255

254256
# PEW
255257
if self.predictor_evaluation_workflow is None:
@@ -261,7 +263,7 @@ def _update_assets(self):
261263
self._predictor_evaluation_workflow = self.project.predictor_evaluation_workflows.get(
262264
self.predictor_evaluation_workflow.uid
263265
)
264-
print("Found existing: {}".format(self.predictor_evaluation_workflow))
266+
logger.info("Found existing: {}".format(self.predictor_evaluation_workflow))
265267

266268
# Design space
267269
if self.design_space is None:
@@ -271,7 +273,7 @@ def _update_assets(self):
271273
)
272274
else:
273275
self._design_space = self.project.design_spaces.get(self.design_space.uid)
274-
print("Found existing: {}".format(self.design_space))
276+
logger.info("Found existing: {}".format(self.design_space))
275277

276278
# Design workflow
277279
if self.design_workflow is None:
@@ -281,7 +283,7 @@ def _update_assets(self):
281283
)
282284
else:
283285
self._design_workflow = self.project.design_workflows.get(self.design_workflow.uid)
284-
print("Found existing: {}".format(self.design_workflow))
286+
logger.info("Found existing: {}".format(self.design_workflow))
285287

286288
def _update_status(self):
287289
"""Update status info based on currently stored assets."""
@@ -659,7 +661,7 @@ def _predictor_evaluation_stage(
659661
if pew.failed():
660662
# Can proceed without raising error, but can't get PEE
661663
self._status = AutoConfigureStatus.PEW_FAILED
662-
warnings.warn(
664+
logger.warning(
663665
"Predictor evaluation workflow failed -- unable to configure execution."
664666
)
665667
elif evaluator is not None:

src/citrine/builders/design_spaces.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csv
2+
from logging import getLogger
23
from uuid import UUID
34

45
from citrine.exceptions import BadRequest
@@ -16,10 +17,11 @@
1617
raise ImportError('numpy is a requirement for the builders module')
1718
from itertools import product
1819
from typing import Mapping, Sequence, List, Optional
19-
from warnings import warn
2020
from citrine.informatics.design_spaces import EnumeratedDesignSpace, DataSourceDesignSpace
2121
from citrine.informatics.descriptors import Descriptor, RealDescriptor
2222

23+
logger = getLogger(__name__)
24+
2325

2426
def enumerate_cartesian_product(
2527
*,
@@ -54,7 +56,7 @@ def enumerate_cartesian_product(
5456
[len(grid_points) for grid_points in design_grid.values()]
5557
) * len(design_grid)
5658
if grid_size > 2E8:
57-
warn(
59+
logger.warning(
5860
"Product design grid contains {n} grid points. This may cause memory issues "
5961
"downstream.".format(n=grid_size)
6062
)
@@ -214,7 +216,7 @@ def cartesian_join_design_spaces(
214216
grid_size = np.prod([len(ds.data) for ds in subspaces]) \
215217
* np.sum([len(ds.data[0]) for ds in subspaces])
216218
if grid_size > 2E8:
217-
warn(
219+
logger.warning(
218220
"Product design grid contains {n} grid points. This may cause memory issues "
219221
"downstream.".format(n=grid_size)
220222
)
@@ -332,7 +334,7 @@ def migrate_enumerated_design_space(*,
332334
try:
333335
project.design_spaces.archive(enumerated_ds.uid)
334336
except BadRequest as err:
335-
warn("Unable to archive design space with uid {}, received the following response: {}"
336-
.format(uid, err.response_text))
337+
logger.warning(f"Unable to archive design space with uid {uid}, "
338+
f"received the following response: {err.response_text}")
337339

338340
return data_source_ds

src/citrine/informatics/predictor_evaluation_metrics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from logging import getLogger
12
from math import isclose
23
from typing import Type, Union, List
3-
from warnings import warn
44

55
from citrine._serialization import properties
66
from citrine._serialization.polymorphic_serializable import PolymorphicSerializable
@@ -16,6 +16,8 @@
1616
'AreaUnderROC',
1717
'CoverageProbability']
1818

19+
logger = getLogger(__name__)
20+
1921

2022
class PredictorEvaluationMetric(PolymorphicSerializable["PredictorEvaluationMetric"]):
2123
"""A metric computed during a Predictor Evaluation Workflow.
@@ -191,7 +193,7 @@ def __init__(self, *, coverage_level: Union[str, float] = "0.683"):
191193
raise ValueError("Coverage level must be between 0 and 1 (non-inclusive).")
192194
_level_float = round(raw_float, 3)
193195
if not isclose(_level_float, raw_float):
194-
warn(
196+
logger.warning(
195197
"Coverage level can only be specified to 3 decimal places."
196198
"Requested level '{requested_level}' will be rounded "
197199
"to {rounded_level}.".format(

src/citrine/informatics/reports.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Type, Dict, TypeVar, Iterable
33
from abc import abstractmethod
44
from itertools import groupby
5-
import warnings
5+
from logging import getLogger
66

77
from citrine._serialization import properties
88
from citrine._serialization.polymorphic_serializable import PolymorphicSerializable
@@ -12,6 +12,8 @@
1212

1313
SelfType = TypeVar('SelfType', bound='Report')
1414

15+
logger = getLogger(__name__)
16+
1517

1618
class Report(PolymorphicSerializable['Report'], AsynchronousObject):
1719
"""[ALPHA] A Citrine Report contains information related to a module.
@@ -162,9 +164,9 @@ def _get_sole_descriptor(it: Iterable):
162164
as_list = list(it)
163165
if len(as_list) > 1:
164166
serialized_descriptors = [d.dump() for d in as_list]
165-
warnings.warn("Warning: found multiple descriptors with the key \'{}\', arbitrarily "
166-
"selecting the first one. The descriptors are: {}"
167-
.format(as_list[0].key, serialized_descriptors), RuntimeWarning)
167+
logger.warning("Warning: found multiple descriptors with the key \'{}\', arbitrarily "
168+
"selecting the first one. The descriptors are: {}"
169+
.format(as_list[0].key, serialized_descriptors))
168170
return as_list[0]
169171

170172
@staticmethod

src/citrine/seeding/find_or_create.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from copy import deepcopy
2-
2+
from logging import getLogger
33
from deprecation import deprecated
44

55
from citrine.exceptions import NotFound
@@ -8,6 +8,8 @@
88
from citrine.informatics.workflows.design_workflow import DesignWorkflow
99
from citrine._rest.collection import CreationType, Collection
1010

11+
logger = getLogger(__name__)
12+
1113

1214
def find_collection(*, collection, name):
1315
"""
@@ -37,7 +39,7 @@ def find_collection(*, collection, name):
3739
raise ValueError("Found multiple collections with name '{}'".format(name))
3840
if len(matching_resources) == 1:
3941
result = matching_resources.pop()
40-
print('Found existing: {}'.format(result))
42+
logger.info('Found existing: {}'.format(result))
4143
return result
4244
else:
4345
return None
@@ -53,7 +55,7 @@ def get_by_name_or_create(*, collection, name, default_provider):
5355
if found:
5456
return found
5557
else:
56-
print('Failed to find resource with name {}, creating one instead.'.format(name))
58+
logger.info('Failed to find resource with name {}, creating one instead.'.format(name))
5759
return default_provider()
5860

5961

@@ -149,7 +151,7 @@ def create_or_update(*, collection: Collection[CreationType], resource: Creation
149151
"""
150152
old_resource = find_collection(collection=collection, name=resource.name)
151153
if old_resource:
152-
print("Updating module: {}".format(resource.name))
154+
logger.info("Updating module: {}".format(resource.name))
153155
# Copy so that passed-in resource is unaffected
154156
new_resource = deepcopy(resource)
155157
new_resource.uid = old_resource.uid
@@ -159,5 +161,5 @@ def create_or_update(*, collection: Collection[CreationType], resource: Creation
159161
new_resource.branch_id = old_resource.branch_id
160162
return collection.update(new_resource)
161163
else:
162-
print("Registering new module: {}".format(resource.name))
164+
logger.info("Registering new module: {}".format(resource.name))
163165
return collection.register(resource)

tests/builders/test_auto_configure.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from uuid import uuid4
23

34
import pytest
@@ -292,7 +293,7 @@ def test_auto_configure_predictor_registration(project):
292293

293294

294295
@mock.patch("citrine.builders.auto_configure.PredictorEvaluationWorkflow", FakePredictorEvaluationWorkflow)
295-
def test_auto_configure_predictor_evaluation(project):
296+
def test_auto_configure_predictor_evaluation(project, caplog):
296297
"""Test the predictor evaluation stage of auto configure."""
297298
config_name = "Test"
298299
resources = default_resources(config_name)
@@ -320,14 +321,16 @@ def test_auto_configure_predictor_evaluation(project):
320321

321322
# Create default w/ an invalid response
322323
with mock.patch("citrine.builders.auto_configure.wait_while_validating", fake_wait_while_failed):
323-
with pytest.warns(UserWarning):
324+
caplog.clear()
325+
with caplog.at_level(logging.WARNING):
324326
auto_config._predictor_evaluation_stage(
325327
predictor=predictor,
326328
evaluator=None,
327329
print_status_info=False
328330
)
329331
assert len(auto_config.assets) == 4
330332
assert auto_config.status == "PREDICTOR EVALUATION WORKFLOW FAILED"
333+
assert any(r.levelno == logging.WARNING for r in caplog.records)
331334

332335
# Create manual w/ a valid response
333336
with mock.patch("citrine.builders.auto_configure.wait_while_validating", fake_wait_while_succeeded):
@@ -341,14 +344,16 @@ def test_auto_configure_predictor_evaluation(project):
341344

342345
# Create manual w/ a failed response
343346
with mock.patch("citrine.builders.auto_configure.wait_while_validating", fake_wait_while_failed):
344-
with pytest.warns(UserWarning):
347+
caplog.clear()
348+
with caplog.at_level(logging.WARNING):
345349
auto_config._predictor_evaluation_stage(
346350
predictor=predictor,
347351
evaluator=evaluator,
348352
print_status_info=False
349353
)
350354
assert len(auto_config.assets) == 4
351355
assert auto_config.status == "PREDICTOR EVALUATION WORKFLOW FAILED"
356+
assert any(r.levelno == logging.WARNING for r in caplog.records)
352357

353358

354359
def test_auto_configure_design_space_build(project):

0 commit comments

Comments
 (0)