Skip to content

Commit 76cc6a2

Browse files
authored
Rename job_service_type -> type (Azure#29603)
* job_service_type -> type * add changelog entry * fix broken type ref * fix rest object serialization * pylint * run black * fix pylint
1 parent 3de65c4 commit 76cc6a2

10 files changed

+65
-64
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
- Fixed issue of spark input/output mode validation doesn't take effect because of wrong type assertion
1414
- Fixed the bug when setting `node.limits.timeout` to a pipeline input.
1515

16+
### Breaking Changes
17+
18+
- Renamed `JobServiceBase.job_service_type` to `type`
19+
1620
### Other Changes
1721

18-
-
22+
-
1923

2024
## 1.5.0 (2023-03-20)
2125

sdk/ml/azure-ai-ml/azure/ai/ml/_schema/job/services.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class JobServiceSchema(JobServiceBaseSchema):
3434
"""This is to support tansformation of job services passed as dict type and internal job services like Custom,
3535
Tracking, Studio set by the system."""
3636

37-
job_service_type = UnionField(
37+
type = UnionField(
3838
[
3939
StringTransformedEnum(
4040
allowed_values=JobServiceTypeNames.NAMES_ALLOWED_FOR_PUBLIC,
@@ -46,55 +46,55 @@ class JobServiceSchema(JobServiceBaseSchema):
4646

4747
@post_load
4848
def make(self, data, **kwargs): # pylint: disable=unused-argument,no-self-use
49-
data.pop("job_service_type", None)
49+
data.pop("type", None)
5050
return JobService(**data)
5151

5252

5353
class TensorBoardJobServiceSchema(JobServiceBaseSchema):
54-
job_service_type = StringTransformedEnum(
54+
type = StringTransformedEnum(
5555
allowed_values=JobServiceTypeNames.EntityNames.TENSOR_BOARD,
5656
pass_original=True,
5757
)
5858
log_dir = fields.Str()
5959

6060
@post_load
6161
def make(self, data, **kwargs): # pylint: disable=unused-argument,no-self-use
62-
data.pop("job_service_type", None)
62+
data.pop("type", None)
6363
return TensorBoardJobService(**data)
6464

6565

6666
class SshJobServiceSchema(JobServiceBaseSchema):
67-
job_service_type = StringTransformedEnum(
67+
type = StringTransformedEnum(
6868
allowed_values=JobServiceTypeNames.EntityNames.SSH,
6969
pass_original=True,
7070
)
7171
ssh_public_keys = fields.Str()
7272

7373
@post_load
7474
def make(self, data, **kwargs): # pylint: disable=unused-argument,no-self-use
75-
data.pop("job_service_type", None)
75+
data.pop("type", None)
7676
return SshJobService(**data)
7777

7878

7979
class VsCodeJobServiceSchema(JobServiceBaseSchema):
80-
job_service_type = StringTransformedEnum(
80+
type = StringTransformedEnum(
8181
allowed_values=JobServiceTypeNames.EntityNames.VS_CODE,
8282
pass_original=True,
8383
)
8484

8585
@post_load
8686
def make(self, data, **kwargs): # pylint: disable=unused-argument,no-self-use
87-
data.pop("job_service_type", None)
87+
data.pop("type", None)
8888
return VsCodeJobService(**data)
8989

9090

9191
class JupyterLabJobServiceSchema(JobServiceBaseSchema):
92-
job_service_type = StringTransformedEnum(
92+
type = StringTransformedEnum(
9393
allowed_values=JobServiceTypeNames.EntityNames.JUPYTER_LAB,
9494
pass_original=True,
9595
)
9696

9797
@post_load
9898
def make(self, data, **kwargs): # pylint: disable=unused-argument,no-self-use
99-
data.pop("job_service_type", None)
99+
data.pop("type", None)
100100
return JupyterLabJobService(**data)

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/job_service.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class JobServiceBase(RestTranslatableMixin, DictMixin):
2525
:type endpoint: str
2626
:param error_message: Any error in the service.
2727
:type error_message: str
28-
:param job_service_type: Endpoint type.
29-
:type job_service_type: str
28+
:param type: Endpoint type.
29+
:type type: str
3030
:param port: Port for endpoint.
3131
:type nodes: str
3232
:param nodes: Indicates whether the service has to run in all nodes.
@@ -43,21 +43,23 @@ def __init__(
4343
self,
4444
*,
4545
endpoint: Optional[str] = None,
46-
job_service_type: Optional[Literal["jupyter_lab", "ssh", "tensor_board", "vs_code"]] = None,
46+
type: Optional[ # pylint: disable=redefined-builtin
47+
Literal["jupyter_lab", "ssh", "tensor_board", "vs_code"]
48+
] = None,
4749
nodes: Optional[Literal["all"]] = None,
4850
status: Optional[str] = None,
4951
port: Optional[int] = None,
5052
properties: Optional[Dict[str, str]] = None,
5153
**kwargs, # pylint: disable=unused-argument
5254
):
5355
self.endpoint = endpoint
54-
self.job_service_type = job_service_type
56+
self.type = type
5557
self.nodes = nodes
5658
self.status = status
5759
self.port = port
5860
self.properties = properties
5961
self._validate_nodes()
60-
self._validate_job_service_type_name()
62+
self._validate_type_name()
6163

6264
def _validate_nodes(self):
6365
if not self.nodes in ["all", None]:
@@ -70,11 +72,10 @@ def _validate_nodes(self):
7072
error_type=ValidationErrorType.INVALID_VALUE,
7173
)
7274

73-
def _validate_job_service_type_name(self):
74-
if self.job_service_type and not self.job_service_type in JobServiceTypeNames.ENTITY_TO_REST.keys():
75+
def _validate_type_name(self):
76+
if self.type and not self.type in JobServiceTypeNames.ENTITY_TO_REST.keys():
7577
msg = (
76-
f"job_service_type should be one of "
77-
f"{JobServiceTypeNames.NAMES_ALLOWED_FOR_PUBLIC}, but received '{self.job_service_type}'."
78+
f"type should be one of " f"{JobServiceTypeNames.NAMES_ALLOWED_FOR_PUBLIC}, but received '{self.type}'."
7879
)
7980
raise ValidationException(
8081
message=msg,
@@ -87,9 +88,7 @@ def _validate_job_service_type_name(self):
8788
def _to_rest_job_service(self, updated_properties: Dict[str, str] = None) -> RestJobService:
8889
return RestJobService(
8990
endpoint=self.endpoint,
90-
job_service_type=JobServiceTypeNames.ENTITY_TO_REST.get(self.job_service_type, None)
91-
if self.job_service_type
92-
else None,
91+
job_service_type=JobServiceTypeNames.ENTITY_TO_REST.get(self.type, None) if self.type else None,
9392
nodes=AllNodes() if self.nodes else None,
9493
status=self.status,
9594
port=self.port,
@@ -113,9 +112,7 @@ def _to_rest_job_services(
113112
def _from_rest_job_service_object(cls, obj: RestJobService):
114113
return cls(
115114
endpoint=obj.endpoint,
116-
job_service_type=JobServiceTypeNames.REST_TO_ENTITY.get(obj.job_service_type, None)
117-
if obj.job_service_type
118-
else None,
115+
type=JobServiceTypeNames.REST_TO_ENTITY.get(obj.job_service_type, None) if obj.job_service_type else None,
119116
nodes="all" if obj.nodes else None,
120117
status=obj.status,
121118
port=obj.port,
@@ -155,9 +152,9 @@ class JobService(JobServiceBase):
155152
156153
:param endpoint: Url for endpoint.
157154
:type endpoint: str
158-
:param job_service_type: Endpoint type.
155+
:param type: Endpoint type.
159156
Accepts "jupyter_lab", "ssh", "tensor_board", "vs_code"
160-
:type job_service_type: str
157+
:type type: str
161158
:param port: Port for endpoint.
162159
:type nodes: str
163160
:param nodes: Indicates whether the service has to run in all nodes.
@@ -196,7 +193,7 @@ class SshJobService(JobServiceBase):
196193
:type ssh_public_keys: str
197194
:param kwargs: A dictionary of additional configuration parameters.
198195
:type kwargs: dict
199-
:ivar job_service_type: Specifies the type of job service. Set automatically to "ssh" for this class.
196+
:ivar type: Specifies the type of job service. Set automatically to "ssh" for this class.
200197
:vartype type: str
201198
"""
202199

@@ -219,7 +216,7 @@ def __init__(
219216
properties=properties,
220217
**kwargs,
221218
)
222-
self.job_service_type = JobServiceTypeNames.EntityNames.SSH
219+
self.type = JobServiceTypeNames.EntityNames.SSH
223220
self.ssh_public_keys = ssh_public_keys
224221

225222
@classmethod
@@ -251,7 +248,7 @@ class TensorBoardJobService(JobServiceBase):
251248
:type log_dir: str
252249
:param kwargs: A dictionary of additional configuration parameters.
253250
:type kwargs: dict
254-
:ivar job_service_type: Specifies the type of job service. Set automatically to "tensor_board" for this class.
251+
:ivar type: Specifies the type of job service. Set automatically to "tensor_board" for this class.
255252
:vartype type: str
256253
"""
257254

@@ -274,7 +271,7 @@ def __init__(
274271
properties=properties,
275272
**kwargs,
276273
)
277-
self.job_service_type = JobServiceTypeNames.EntityNames.TENSOR_BOARD
274+
self.type = JobServiceTypeNames.EntityNames.TENSOR_BOARD
278275
self.log_dir = log_dir
279276

280277
@classmethod
@@ -304,7 +301,7 @@ class JupyterLabJobService(JobServiceBase):
304301
:type status: str
305302
:param kwargs: A dictionary of additional configuration parameters.
306303
:type kwargs: dict
307-
:ivar job_service_type: Specifies the type of job service. Set automatically to "jupyter_lab" for this class.
304+
:ivar type: Specifies the type of job service. Set automatically to "jupyter_lab" for this class.
308305
:vartype type: str
309306
"""
310307

@@ -326,7 +323,7 @@ def __init__(
326323
properties=properties,
327324
**kwargs,
328325
)
329-
self.job_service_type = JobServiceTypeNames.EntityNames.JUPYTER_LAB
326+
self.type = JobServiceTypeNames.EntityNames.JUPYTER_LAB
330327

331328
@classmethod
332329
def _from_rest_object(cls, obj: RestJobService) -> "JupyterLabJobService":
@@ -352,7 +349,7 @@ class VsCodeJobService(JobServiceBase):
352349
:type status: str
353350
:param kwargs: A dictionary of additional configuration parameters.
354351
:type kwargs: dict
355-
:ivar job_service_type: Specifies the type of job service. Set automatically to "vs_code" for this class.
352+
:ivar type: Specifies the type of job service. Set automatically to "vs_code" for this class.
356353
:vartype type: str
357354
"""
358355

@@ -374,7 +371,7 @@ def __init__(
374371
properties=properties,
375372
**kwargs,
376373
)
377-
self.job_service_type = JobServiceTypeNames.EntityNames.VS_CODE
374+
self.type = JobServiceTypeNames.EntityNames.VS_CODE
378375

379376
@classmethod
380377
def _from_rest_object(cls, obj: RestJobService) -> "VsCodeJobService":

sdk/ml/azure-ai-ml/tests/dsl/e2etests/test_dsl_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,9 +2571,9 @@ def pipeline(job_in_number, job_in_other_number, job_in_path):
25712571
assert "Studio" in default_services
25722572
assert "Tracking" in default_services
25732573
assert default_services["Studio"]["endpoint"].startswith("https://ml.azure.com/runs/")
2574-
assert default_services["Studio"]["job_service_type"] == "Studio"
2574+
assert default_services["Studio"]["type"] == "Studio"
25752575
assert default_services["Tracking"]["endpoint"].startswith("azureml://")
2576-
assert default_services["Tracking"]["job_service_type"] == "Tracking"
2576+
assert default_services["Tracking"]["type"] == "Tracking"
25772577

25782578
def test_group_outputs_description_overwrite(self, client):
25792579
# test group outputs description overwrite

sdk/ml/azure-ai-ml/tests/dsl/unittests/test_command_builder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,9 @@ def test_spark_job_with_additional_conf(self):
841841

842842
def test_command_services_nodes(self) -> None:
843843
services = {
844-
"my_jupyterlab": JobService(job_service_type="jupyter_lab", nodes="all"),
844+
"my_jupyterlab": JobService(type="jupyter_lab", nodes="all"),
845845
"my_tensorboard": JobService(
846-
job_service_type="tensor_board",
846+
type="tensor_board",
847847
properties={
848848
"logDir": "~/tblog",
849849
},
@@ -867,14 +867,14 @@ def test_command_services_nodes(self) -> None:
867867

868868
def test_command_services(self) -> None:
869869
services = {
870-
"my_ssh": JobService(job_service_type="ssh"),
870+
"my_ssh": JobService(type="ssh"),
871871
"my_tensorboard": JobService(
872-
job_service_type="tensor_board",
872+
type="tensor_board",
873873
properties={
874874
"logDir": "~/tblog",
875875
},
876876
),
877-
"my_jupyterlab": JobService(job_service_type="jupyter_lab"),
877+
"my_jupyterlab": JobService(type="jupyter_lab"),
878878
}
879879
rest_services = {
880880
"my_ssh": {"job_service_type": "SSH"},

sdk/ml/azure-ai-ml/tests/dsl/unittests/test_dsl_pipeline_with_specific_nodes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,15 +2764,15 @@ def sample_pipeline_with_new_services():
27642764

27652765
def test_pipeline_with_command_services_with_deprecatable_JobService(self):
27662766
services = {
2767-
"my_ssh": JobService(job_service_type="ssh"),
2767+
"my_ssh": JobService(type="ssh"),
27682768
"my_tensorboard": JobService(
2769-
job_service_type="tensor_board",
2769+
type="tensor_board",
27702770
properties={
27712771
"logDir": "~/tblog",
27722772
},
27732773
),
2774-
"my_jupyterlab": JobService(job_service_type="jupyter_lab"),
2775-
"my_vscode": JobService(job_service_type="vs_code"),
2774+
"my_jupyterlab": JobService(type="jupyter_lab"),
2775+
"my_vscode": JobService(type="vs_code"),
27762776
}
27772777
rest_services = {
27782778
"my_ssh": {"job_service_type": "SSH"},
@@ -2827,7 +2827,7 @@ def sample_pipeline():
28272827
assert isinstance(node_services.get("my_vscode"), VsCodeJobService)
28282828

28292829
# test set services in pipeline
2830-
new_services = {"my_jupyter": JobService(job_service_type="jupyter_lab")}
2830+
new_services = {"my_jupyter": JobService(type="jupyter_lab")}
28312831
rest_new_services = {"my_jupyter": {"job_service_type": "JupyterLab"}}
28322832

28332833
@dsl.pipeline()

sdk/ml/azure-ai-ml/tests/test_configs/pipeline_jobs/helloworld_pipeline_job_with_node_services.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
code: "./"
2020
services:
2121
"my_ssh":
22-
job_service_type: "ssh"
22+
type: "ssh"
2323
ssh_public_keys: "xyz123"
2424
"my_tensorboard":
25-
job_service_type: "tensor_board"
25+
type: "tensor_board"
2626
log_dir: "~/tblog" # where you want to store the tensor_board output
2727
"my_jupyterlab":
28-
job_service_type: "jupyter_lab"
28+
type: "jupyter_lab"
2929
"my_vscode":
30-
job_service_type: "vs_code"
30+
type: "vs_code"

sdk/ml/azure-ai-ml/tests/test_configs/pipeline_jobs/helloworld_pipeline_job_with_node_services_inline_job.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33
1515
services:
1616
"my_ssh":
17-
job_service_type: "ssh"
17+
type: "ssh"
1818
ssh_public_keys: "xyz123"
1919
"my_tensorboard":
20-
job_service_type: "tensor_board"
20+
type: "tensor_board"
2121
log_dir: "~/tblog" # where you want to store the tensor_board output
2222
"my_jupyterlab":
23-
job_service_type: "jupyter_lab"
23+
type: "jupyter_lab"
2424
"my_vscode":
25-
job_service_type: "vs_code"
25+
type: "vs_code"

sdk/ml/azure-ai-ml/tests/test_configs/pipeline_jobs/helloworld_pipeline_job_with_node_services_inline_job_with_properties.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33
1515
services:
1616
"my_ssh":
17-
job_service_type: "ssh"
17+
type: "ssh"
1818
properties:
1919
sshPublicKeys: "xyz123"
2020
"my_tensorboard":
21-
job_service_type: "tensor_board"
21+
type: "tensor_board"
2222
properties:
2323
logDir: "~/tblog" # where you want to store the tensor_board output
2424
"my_jupyterlab":
25-
job_service_type: "jupyter_lab"
25+
type: "jupyter_lab"
2626
"my_vscode":
27-
job_service_type: "vs_code"
27+
type: "vs_code"

sdk/ml/azure-ai-ml/tests/test_configs/pipeline_jobs/helloworld_pipeline_job_with_node_services_with_properties.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919
code: "./"
2020
services:
2121
"my_ssh":
22-
job_service_type: "ssh"
22+
type: "ssh"
2323
properties:
2424
sshPublicKeys: "xyz123"
2525
"my_tensorboard":
26-
job_service_type: "tensor_board"
26+
type: "tensor_board"
2727
properties:
2828
logDir: "~/tblog" # where you want to store the tensor_board output
2929
"my_jupyterlab":
30-
job_service_type: "jupyter_lab"
30+
type: "jupyter_lab"
3131
"my_vscode":
32-
job_service_type: "vs_code"
32+
type: "vs_code"
3333

0 commit comments

Comments
 (0)