Skip to content

Commit dc7fc74

Browse files
authored
[ml] Enable strict sphinx check (#34688)
* Remove Optional type annotation from get() methods * Remove duplicate overloads * Fix sphinx errors * Fix indentation * Turn on strict sphinx check * Implicitly expose search_space and _credentials classes to avoid duplicate object exposures * Add deprecation warning message for imports and update CHANGELOG * Update formatting * Ignore mypy error
1 parent 863ccdd commit dc7fc74

File tree

12 files changed

+159
-48
lines changed

12 files changed

+159
-48
lines changed

sdk/ml/azure-ai-ml/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010

1111
### Other Changes
1212

13+
- The following classes will still be able to be imported from `azure.ai.ml`, but the import is deprecated and emits a warning. Instead, please import them from `azure.ai.ml.entities`.
14+
- `AmlTokenConfiguration`
15+
- `ManagedIdentityConfiguration`
16+
- `UserIdentityConfiguration`
17+
- The following classes will still be able to be imported from `azure.ai.ml.entities`, but the import is deprecated and emits a warning. Instead, please import them from `azure.ai.ml.sweep`.
18+
- `Choice`
19+
- `Uniform`
20+
- `LogUniform`
21+
- `QLogUniform`
22+
- `QUniform`
23+
- `QLogNormal`
24+
- `QNormal`
25+
- `LogNormal`
26+
- `Normal`
27+
- `Randint`
28+
1329
## 1.14.0 (2024-03-11)
1430

1531
### Features Added

sdk/ml/azure-ai-ml/azure/ai/ml/__init__.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
66

77
import logging
8+
from typing import Any, Optional
89

910
# from .entities._builders.parallel_func import parallel
1011
from azure.ai.ml.entities._inputs_outputs import Input, Output
@@ -14,7 +15,6 @@
1415
from ._version import VERSION
1516
from .entities._builders.command_func import command
1617
from .entities._builders.spark_func import spark
17-
from .entities._credentials import AmlTokenConfiguration, ManagedIdentityConfiguration, UserIdentityConfiguration
1818
from .entities._job.distribution import MpiDistribution, PyTorchDistribution, RayDistribution, TensorFlowDistribution
1919
from .entities._load_functions import (
2020
load_batch_deployment,
@@ -52,9 +52,6 @@
5252
"PyTorchDistribution",
5353
"TensorFlowDistribution",
5454
"RayDistribution",
55-
"ManagedIdentityConfiguration",
56-
"AmlTokenConfiguration",
57-
"UserIdentityConfiguration",
5855
"load_batch_deployment",
5956
"load_batch_endpoint",
6057
"load_component",
@@ -77,3 +74,35 @@
7774
]
7875

7976
__version__ = VERSION
77+
78+
79+
# Allow importing these types for backwards compatibility
80+
81+
82+
def __getattr__(name: str):
83+
requested: Optional[Any] = None
84+
85+
if name == "AmlTokenConfiguration":
86+
from .entities._credentials import AmlTokenConfiguration
87+
88+
requested = AmlTokenConfiguration
89+
if name == "ManagedIdentityConfiguration":
90+
from .entities._credentials import ManagedIdentityConfiguration
91+
92+
requested = ManagedIdentityConfiguration
93+
if name == "UserIdentityConfiguration":
94+
from .entities._credentials import UserIdentityConfiguration
95+
96+
requested = UserIdentityConfiguration
97+
98+
if requested:
99+
if not getattr(__getattr__, "warning_issued", False):
100+
logging.warning(
101+
" %s will be removed from the azure.ai.ml namespace in a future release."
102+
" Please use the azure.ai.ml.entities namespace instead.",
103+
name,
104+
)
105+
__getattr__.warning_issued = True # type: ignore[attr-defined]
106+
return requested
107+
108+
raise AttributeError(f"module 'azure.ai.ml' has no attribute {name}")

sdk/ml/azure-ai-ml/azure/ai/ml/entities/__init__.py

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# pylint: disable=naming-mismatch
1010
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1111

12+
import logging
13+
from typing import Any, Optional
14+
1215
from azure.ai.ml._restclient.v2022_10_01.models import CreatedByType
1316
from azure.ai.ml._restclient.v2022_10_01_preview.models import UsageUnit
1417

@@ -138,18 +141,6 @@
138141
from ._job.spark_job import SparkJob
139142
from ._job.spark_job_entry import SparkJobEntry, SparkJobEntryType
140143
from ._job.spark_resource_configuration import SparkResourceConfiguration
141-
from ._job.sweep.search_space import (
142-
Choice,
143-
LogNormal,
144-
LogUniform,
145-
Normal,
146-
QLogNormal,
147-
QLogUniform,
148-
QNormal,
149-
QUniform,
150-
Randint,
151-
Uniform,
152-
)
153144
from ._monitoring.alert_notification import AlertNotification
154145
from ._monitoring.compute import ServerlessSparkCompute
155146
from ._monitoring.definition import MonitorDefinition
@@ -325,16 +316,6 @@
325316
"ParallelComponent",
326317
"CommandComponent",
327318
"SparkComponent",
328-
"Choice",
329-
"Normal",
330-
"LogNormal",
331-
"QNormal",
332-
"QLogNormal",
333-
"Randint",
334-
"Uniform",
335-
"QUniform",
336-
"LogUniform",
337-
"QLogUniform",
338319
"ResourceRequirementsSettings",
339320
"ResourceSettings",
340321
"AssignedUserConfiguration",
@@ -472,3 +453,62 @@
472453
"RequestLogging",
473454
"NoneCredentialConfiguration",
474455
]
456+
457+
# Allow importing these types for backwards compatibility
458+
459+
460+
def __getattr__(name: str):
461+
requested: Optional[Any] = None
462+
463+
if name == "Choice":
464+
from ..sweep import Choice
465+
466+
requested = Choice
467+
if name == "LogNormal":
468+
from ..sweep import LogNormal
469+
470+
requested = LogNormal
471+
if name == "LogUniform":
472+
from ..sweep import LogUniform
473+
474+
requested = LogUniform
475+
if name == "Normal":
476+
from ..sweep import Normal
477+
478+
requested = Normal
479+
if name == "QLogNormal":
480+
from ..sweep import QLogNormal
481+
482+
requested = QLogNormal
483+
if name == "QLogUniform":
484+
from ..sweep import QLogUniform
485+
486+
requested = QLogUniform
487+
if name == "QNormal":
488+
from ..sweep import QNormal
489+
490+
requested = QNormal
491+
if name == "QUniform":
492+
from ..sweep import QUniform
493+
494+
requested = QUniform
495+
if name == "Randint":
496+
from ..sweep import Randint
497+
498+
requested = Randint
499+
if name == "Uniform":
500+
from ..sweep import Uniform
501+
502+
requested = Uniform
503+
504+
if requested:
505+
if not getattr(__getattr__, "warning_issued", False):
506+
logging.warning(
507+
" %s will be removed from the azure.ai.ml.entities namespace in a future release."
508+
" Please import from the azure.ai.ml.sweep namespace instead.",
509+
name,
510+
)
511+
__getattr__.warning_issued = True # type: ignore[attr-defined]
512+
return requested
513+
514+
raise AttributeError(f"module 'azure.ai.ml.entities' has no attribute {name}")

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/pipeline/_attr_dict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
V = TypeVar("V")
1313

1414

15-
class _AttrDict(Generic[K, V], dict, ABC):
15+
class _AttrDict(Generic[K, V], Dict, ABC):
1616
"""This class is used for accessing values with instance.some_key. It supports the following scenarios:
1717
1818
1. Setting arbitrary attribute, eg: obj.resource_layout.node_count = 2
@@ -34,6 +34,7 @@ def __init__(self, allowed_keys: Optional[Dict] = None, **kwargs: Any):
3434
3535
:param allowed_keys: A dictionary of keys that allowed to set as arbitrary attributes. None means all keys can
3636
be set as arbitrary attributes.
37+
3738
:type dict
3839
:param kwargs: A dictionary of additional configuration parameters.
3940
:type kwargs: dict

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/parameterized_sweep.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,19 @@ def __init__(
6666
:param early_termination: Early termination policy for sweep job.
6767
:type early_termination: ~azure.ai.ml.entities._job.sweep.early_termination_policy.EarlyTerminationPolicy
6868
:param search_space: Search space for sweep job.
69-
:type search_space: Dict[str, Union[~azure.ai.ml.sweep.Choice, ~azure.ai.ml.sweep.LogNormal,
70-
~azure.ai.ml.sweep.LogUniform, ~azure.ai.ml.sweep.Normal, ~azure.ai.ml.sweep.QLogNormal,
71-
~azure.ai.ml.sweep.QLogUniform, ~azure.ai.ml.sweep.QNormal, ~azure.ai.ml.sweep.QUniform,
72-
~azure.ai.ml.sweep.Randint, ~azure.ai.ml.sweep.Uniform]]
69+
:type search_space: Dict[str, Union[
70+
~azure.ai.ml.sweep.Choice,
71+
~azure.ai.ml.sweep.LogNormal,
72+
~azure.ai.ml.sweep.LogUniform,
73+
~azure.ai.ml.sweep.Normal,
74+
~azure.ai.ml.sweep.QLogNormal,
75+
~azure.ai.ml.sweep.QLogUniform,
76+
~azure.ai.ml.sweep.QNormal,
77+
~azure.ai.ml.sweep.QUniform,
78+
~azure.ai.ml.sweep.Randint,
79+
~azure.ai.ml.sweep.Uniform
80+
81+
]]
7382
:param queue_settings: Queue settings for sweep job.
7483
:type queue_settings: ~azure.ai.ml.entities.QueueSettings
7584
:param resources: Compute Resource configuration for the job.

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/search_space.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def _from_rest_object(cls, obj: List) -> "Randint":
267267

268268
class Uniform(SweepDistribution):
269269
"""
270-
:noindex:
271270
272271
Uniform distribution configuration.
273272

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/sweep/sweep_job.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,21 @@ class SweepJob(Job, ParameterizedSweep, JobIOMixin):
8888
:paramtype identity: Union[
8989
~azure.ai.ml.ManagedIdentityConfiguration,
9090
~azure.ai.ml.AmlTokenConfiguration,
91-
~azure.ai.ml.UserIdentityConfiguration]
91+
~azure.ai.ml.UserIdentityConfiguration
92+
93+
]
94+
9295
:keyword inputs: Inputs to the command.
9396
:paramtype inputs: dict
9497
:keyword outputs: Mapping of output data bindings used in the job.
9598
:paramtype outputs: dict[str, ~azure.ai.ml.Output]
9699
:keyword sampling_algorithm: The hyperparameter sampling algorithm to use over the `search_space`. Defaults to
97100
"random".
101+
98102
:paramtype sampling_algorithm: str
99103
:keyword search_space: Dictionary of the hyperparameter search space. The key is the name of the hyperparameter
100104
and the value is the parameter expression.
105+
101106
:paramtype search_space: Dict
102107
:keyword objective: Metric to optimize for.
103108
:paramtype objective: Objective
@@ -111,12 +116,17 @@ class SweepJob(Job, ParameterizedSweep, JobIOMixin):
111116
~azure.ai.ml.entities.CommandComponent
112117
113118
]
119+
114120
:keyword early_termination: The early termination policy to use. A trial job is canceled
115121
when the criteria of the specified policy are met. If omitted, no early termination policy will be applied.
122+
116123
:paramtype early_termination: Union[
117124
~azure.mgmt.machinelearningservices.models.BanditPolicy,
118125
~azure.mgmt.machinelearningservices.models.MedianStoppingPolicy,
119-
~azure.mgmt.machinelearningservices.models.TruncationSelectionPolicy]
126+
~azure.mgmt.machinelearningservices.models.TruncationSelectionPolicy
127+
128+
]
129+
120130
:keyword limits: Limits for the sweep job.
121131
:paramtype limits: ~azure.ai.ml.entities.SweepJobLimits
122132
:keyword queue_settings: Queue settings for the job.

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_workspace/connections/workspace_connection.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,31 @@
44

55
# pylint: disable=protected-access
66

7+
import warnings
78
from os import PathLike
89
from pathlib import Path
9-
import warnings
1010
from typing import IO, Any, AnyStr, Dict, List, Optional, Type, Union, cast
1111

12+
from azure.ai.ml._restclient.v2023_08_01_preview.models import (
13+
WorkspaceConnectionPropertiesV2BasicResource as RestWorkspaceConnection,
14+
)
1215
from azure.ai.ml._restclient.v2024_01_01_preview.models import (
1316
ConnectionCategory,
1417
NoneAuthTypeWorkspaceConnectionProperties,
1518
)
16-
from azure.ai.ml._restclient.v2023_08_01_preview.models import (
17-
WorkspaceConnectionPropertiesV2BasicResource as RestWorkspaceConnection,
18-
)
1919
from azure.ai.ml._schema.workspace.connections.workspace_connection import WorkspaceConnectionSchema
2020
from azure.ai.ml._utils._experimental import experimental
2121
from azure.ai.ml._utils.utils import _snake_to_camel, camel_to_snake, dump_yaml_to_file
22-
from azure.ai.ml.constants._common import (
23-
BASE_PATH_CONTEXT_KEY,
24-
PARAMS_OVERRIDE_KEY,
25-
WorkspaceConnectionTypes,
26-
)
22+
from azure.ai.ml.constants._common import BASE_PATH_CONTEXT_KEY, PARAMS_OVERRIDE_KEY, WorkspaceConnectionTypes
2723
from azure.ai.ml.entities._credentials import (
2824
AccessKeyConfiguration,
2925
ApiKeyConfiguration,
3026
ManagedIdentityConfiguration,
27+
NoneCredentialConfiguration,
3128
PatTokenConfiguration,
3229
SasTokenConfiguration,
3330
ServicePrincipalConfiguration,
3431
UsernamePasswordConfiguration,
35-
NoneCredentialConfiguration,
3632
_BaseIdentityConfiguration,
3733
)
3834
from azure.ai.ml.entities._resource import Resource
@@ -174,6 +170,7 @@ def credentials(
174170
~azure.ai.ml.entities.ServicePrincipalConfiguration,
175171
~azure.ai.ml.entities.AccessKeyConfiguration,
176172
~azure.ai.ml.entities.ApiKeyConfiguration
173+
177174
]
178175
"""
179176
return self._credentials
@@ -373,8 +370,8 @@ def _get_entity_class_from_type(cls, conn_type: Optional[str]) -> Type:
373370
from .workspace_connection_subtypes import (
374371
AzureAISearchWorkspaceConnection,
375372
AzureAIServiceWorkspaceConnection,
376-
AzureOpenAIWorkspaceConnection,
377373
AzureBlobStoreWorkspaceConnection,
374+
AzureOpenAIWorkspaceConnection,
378375
)
379376

380377
# Connection categories don't perfectly follow perfect camel casing, so lower

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def archive(
415415
:end-before: [END model_operations_archive]
416416
:language: python
417417
:dedent: 8
418-
:caption: Archive a model example.
418+
:caption: Archive a model.
419419
"""
420420
_archive_or_restore(
421421
asset_operations=self,
@@ -451,7 +451,7 @@ def restore(
451451
:end-before: [END model_operations_restore]
452452
:language: python
453453
:dedent: 8
454-
:caption: Restore a model example.
454+
:caption: Restore an archived model.
455455
"""
456456
_archive_or_restore(
457457
asset_operations=self,

sdk/ml/azure-ai-ml/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pyright = false
44
type_check_samples = false
55
verifytypes = false
66
pylint = true
7-
strict_sphinx = false
7+
strict_sphinx = true
88

99

1010
[tool.isort]

0 commit comments

Comments
 (0)