Skip to content

Add DictMixin to easy AML SDK classes #26365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 11, 2022
4 changes: 2 additions & 2 deletions sdk/ml/azure-ai-ml/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 0.2.0 (Unreleased)

### Features Added

- Most configuration classes from the entity package now implement the standard mapping protocol.
### Breaking Changes

### Bugs Fixed
Expand All @@ -15,7 +15,7 @@
- Dropped support for Python 3.6. The Python versions supported for this release are 3.7-3.10.

### Features Added

### Breaking Changes
- OnlineDeploymentOperations.delete has been renamed to begin_delete.
- Datastore credentials are switched to use unified credential configuration classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from azure.ai.ml.constants._common import BASE_PATH_CONTEXT_KEY, TYPE
from azure.ai.ml.constants._compute import ComputeDefaults, ComputeType
from azure.ai.ml.entities._compute.compute import Compute, NetworkSettings
from azure.ai.ml.entities._mixins import DictMixin
from azure.ai.ml.entities._util import load_from_dict
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, ValidationException
from azure.ai.ml.entities._credentials import IdentityConfiguration
Expand Down Expand Up @@ -70,7 +71,7 @@ def ssh_port(self) -> str:
return self._ssh_port


class AssignedUserConfiguration:
class AssignedUserConfiguration(DictMixin):
"""Settings to create a compute on behalf of another user."""

def __init__(self, *, user_tenant_id: str, user_object_id: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

from azure.ai.ml._restclient.v2021_10_01.models import CodeConfiguration as RestCodeConfiguration
from azure.ai.ml.entities._assets import Code
from azure.ai.ml.entities._mixins import DictMixin
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, ValidationException

module_logger = logging.getLogger(__name__)


class CodeConfiguration:
class CodeConfiguration(DictMixin):
"""CodeConfiguration.

:param code: Code entity, defaults to None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def _data_binding(self) -> str:
"""Return data binding string representation for this input/output."""
raise NotImplementedError()

# Why did we have this function? It prevents the DictMixin from being applied.
# Unclear if we explicitly do NOT want the mapping protocol to be applied to this, or it this was just
# confirmation that it didn't at the time.
def keys(self):
# This property is introduced to raise catchable Exception in marshmallow mapping validation trial.
raise TypeError(f"'{type(self).__name__}' object is not a mapping")
Expand Down
6 changes: 6 additions & 0 deletions sdk/ml/azure-ai-ml/azure/ai/ml/entities/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def _from_rest_object(cls, obj: Any) -> Any:


class DictMixin(object):
def __contains__(self, item):
return self.__dict__.__contains__(item)

def __iter__(self):
return self.__dict__.__iter__()

def __setitem__(self, key, item):
# type: (Any, Any) -> None
self.__dict__[key] = item
Expand Down