Skip to content

Iterations

Iteration

Iteration(
    id, index, phase, status=IterationStatus.NotStarted
)

Represent a Vectice iteration.

Iterations reflect the model development and test cycles completed by data scientists until a fully functional algorithm is ready for deployment. Each iteration contains the sequence of steps defined at the Phase and acts as a guardrail for data scientists to provide their updates.

Typical usage example:

my_iteration = my_phase.iteration()

my_iteration.step_cleaning = my_dataset
# you can append assets of the same types (datasets/models) with +=
my_iteration.step_cleaning += my_other_dataset

my_iteration.step_model = my_model
my_iteration.step_model += my_other_model

If steps are added to a phase after iterations have been created and completed, these steps won't appear in these iterations.

📁 iteration 1
├── 📄 step 1
├── 📄 step 2
└── 📄 step 3

Phases and Steps Definitions are created in the Vectice App, Iterations are created from the Vectice Python API.

To create a new iteration:

my_iteration = my_phase.iteration()

Vectice users shouldn't need to instantiate Iterations manually, but here are the iteration parameters.

Parameters:

Name Type Description Default
id int

The iteration identifier.

required
index int

The index of the iteration.

required
phase Phase

The project to which the iteration belongs.

required
status IterationStatus

The status of the iteration.

IterationStatus.NotStarted
Source code in src/vectice/models/iteration.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def __init__(
    self,
    id: int,
    index: int,
    phase: Phase,
    status: IterationStatus = IterationStatus.NotStarted,
):
    """Initialize an iteration.

    Vectice users shouldn't need to instantiate Iterations manually,
    but here are the iteration parameters.

    Parameters:
        id: The iteration identifier.
        index: The index of the iteration.
        phase: The project to which the iteration belongs.
        status: The status of the iteration.
    """
    self.__dict__ = {}
    self._id = id
    self._index = index
    self._phase = phase
    self._status = status
    self._client: Client = self._phase._client
    self._model: Model | None = None
    self._current_step: Step | None = None
    self._steps = self._populate_steps()

completed property

completed: bool

Whether this iteration is completed.

Returns:

Type Description
bool

Whether the iteration is completed.

connection property

connection: Connection

The connection to which this iteration belongs.

Returns:

Type Description
Connection

The connection to which this iteration belongs.

id writable property

id: int

The iteration's identifier.

Returns:

Type Description
int

The iteration's identifier.

index property

index: int

The iteration's index.

Returns:

Type Description
int

The iteration's index.

model writable property

model: Model | None

Deprecated. Use steps' model instead.

Returns:

Type Description
Model | None

The iteration's model.

modeling_dataset writable property

modeling_dataset: None

Deprecated. Use steps' modeling_dataset instead.

Raises:

Type Description
DeprecationError

Always.

phase property

phase: Phase

The phase to which this iteration belongs.

Returns:

Type Description
Phase

The phase to which this iteration belongs.

project property

project: Project

The project to which this iteration belongs.

Returns:

Type Description
Project

The project to which this iteration belongs.

properties property

properties: dict

The iteration's identifier and index.

Returns:

Type Description
dict

A dictionary containing the id and index items.

step_names property

step_names: list[str]

The names of the steps required in this iteration.

Returns:

Type Description
list[str]

The steps names.

steps property

steps: list[Step]

The steps required in this iteration.

Returns:

Type Description
list[Step]

The steps required in this iteration.

workspace property

workspace: Workspace

The workspace to which this iteration belongs.

Returns:

Type Description
Workspace

The workspace to which this iteration belongs.

cancel

cancel()

Cancel the iteration by abandoning all unfinished steps.

Source code in src/vectice/models/iteration.py
347
348
349
350
351
352
def cancel(self) -> None:
    """Cancel the iteration by abandoning all unfinished steps."""
    iteration_input = IterationInput(status=IterationStatus.Abandoned.name)
    self._client.update_iteration(self.id, iteration_input)
    self._status = IterationStatus.Abandoned
    _logger.info(f"Iteration with index {self.index} canceled.")

complete

complete()

Mark the iteration as completed.

Source code in src/vectice/models/iteration.py
354
355
356
357
358
359
360
361
def complete(self) -> None:
    """Mark the iteration as completed."""
    if self._status is IterationStatus.Abandoned:
        raise VecticeException("The iteration is canceled and cannot be completed.")
    iteration_input = IterationInput(status=IterationStatus.Completed.name)
    self._client.update_iteration(self.id, iteration_input)
    self._status = IterationStatus.Completed
    _logger.info(f"Iteration with index {self.index} completed.")

list_steps

list_steps()

Prints a list of steps belonging to the iteration in a tabular format, limited to the first 10 items. A link is provided to view the remaining steps.

Returns:

Type Description
None

None

Source code in src/vectice/models/iteration.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def list_steps(self) -> None:
    """Prints a list of steps belonging to the iteration in a tabular format, limited to the first 10 items. A link is provided to view the remaining steps.

    Returns:
        None
    """
    steps_output = sorted(self._client.list_steps(self.phase.id, self.index), key=lambda x: x.index)
    user_name, _ = _get_last_user_and_default_workspace(self._client)

    rich_table = Table(expand=True, show_edge=False)

    rich_table.add_column("step id", justify="left", no_wrap=True, min_width=5, max_width=5)
    rich_table.add_column("shortcut", justify="left", no_wrap=True, min_width=5, max_width=20)
    rich_table.add_column("artifacts", justify="left", no_wrap=True, min_width=5, max_width=15)
    rich_table.add_column("comment", justify="left", no_wrap=True, min_width=5, max_width=20)

    def _get_artifact_id(artifact) -> int | None:
        if artifact.dataset_version_id:
            return int(artifact.dataset_version_id)
        if artifact.model_version_id:
            return int(artifact.model_version_id)
        if artifact.entity_file_id:
            return int(artifact.entity_file_id)
        return None

    for count, step in enumerate(steps_output, 1):
        if count > 10:
            break
        step_text = step.text if step.text != "None" else None
        steps_started = False
        # TODO no artifacts, remove nested
        for number, artifact in enumerate(step.artifacts, 1):
            artifact_id = _get_artifact_id(artifact)
            if not steps_started:
                rich_table.add_row(
                    str(step.id), step.slug, f"{number}. {artifact.type.value} {artifact_id}", step_text
                )
            if steps_started:
                rich_table.add_row(None, None, f"{number}. {artifact.type.value} {artifact_id}", None)
            steps_started = True
        if not step.artifacts:
            rich_table.add_row(
                str(step.id),
                step.slug,
                None,
                step_text,
            )
    if not steps_output:
        rich_table.add_row(
            None,
            None,
            None,
            None,
        )
    description = f"""There are {len(steps_output)} steps in iteration {self.index!r}."""
    tips = dedent(
        """
    >> To access a specific step, use iteration.step(Step ID)
    >> To access an array of steps, use iteration.steps"""
    ).lstrip()
    link = dedent(
        f"""
    For quick access to the list of steps in the Vectice web app, visit:
    {self._client.auth._API_BASE_URL}/project/phase/iteration?w={self.workspace.id}&iterationId={self.id}"""
    ).lstrip()

    _temp_print(description)
    _temp_print(table=rich_table)
    _temp_print(tips)
    _temp_print(link)

step

step(step)

Get a step by name.

Step names are configured for a phase by the Vectice administrator.

Parameters:

Name Type Description Default
step str

The name of the step

required

Returns:

Type Description
Step

A step.

Source code in src/vectice/models/iteration.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
def step(self, step: str) -> Step:
    """Get a step by name.

    Step names are configured for a phase by the Vectice administrator.

    Parameters:
        step: The name of the step

    Returns:
        A step.
    """
    steps_output = self._client.get_step_by_name(step, self.id)
    _logger.debug(f"Step: {steps_output.name} successfully retrieved.")
    with ignore_deprecation_warnings():
        step_object = _get_step_type(
            id=steps_output.id,
            iteration=self,
            name=steps_output.name,
            index=steps_output.index,
            slug=steps_output.slug,
            description=steps_output.description,
            completed=steps_output.completed or None,
            artifacts=steps_output.artifacts,
            step_type=steps_output.step_type,
            text=steps_output.text,
        )
    self._current_step = step_object
    return step_object