Interaction with REPEAT VISION platform#

Interaction module with REPEAT VISION

class repeat.repeat_model.Application(user: pydantic.dataclasses.dataclass, address: str = 'https://app.repeat.vision', common_path: str = '/backend/api/v1/public')#

Setup class for connection to REPEAT VISION model

Parameters:
userrepeat.repeat_user.User

An instance of the User class with description of user parameters necessary to authorize and further use of the repeat module

addressstr, optional

Адрес сайта платформы REPEAT VISION. Значение по умолчанию 'https://app.repeat.vision'. Аргументу address может присваиваться другой адрес платформы в случае использования дистрибутива REPEAT VISION.

Changed in version 1.3.0: The default value of the address argument has been changed to 'https://app.repeat.vision'

common_pathstr

Общая часть пути к методам REST API REPEAT VISION. Значение по умолчанию '/backend/api/v1/public'. Аргументу common_path может присваиваться другой путь к методам платформы в случае использования дистрибутива REPEAT VISION, например, common_path = '/api/v1/public'.

Deprecated since version 2.0.0: Аргумент common_path будет заменён на is_cloud : bool со значением по умолчанию True для доступа к методам REST API облачной версии REPEAT VISION. В случае использования дистрибутива аргументу is_cloud необходимо будет присвоить значение False.

Attributes:
projectsdict

A set of user projects. Key: str | int in projects - unique project identifier. Value: dict in projects - project description.

Changed in version 2.0.0: The type will change to pandas.Series. In the projects attribute, the str key will become the project ID, and the str value will be the project name. Additional information about projects can be obtained using the :py:meth:get_projects method.

Returns:
None

Examples

>>> from repeat import User, Application
>>>  
>>> user = User(token = "уникальный токен из кабинета пользователя REPEAT VISION")
>>> app = Application(user)
>>> print(app.projects)
>>> # {"21425d1a-70f9-4bke-8140-81bd312bd91b": {
>>> #   "userId": "11125d1a-70f9-5bke-5145-81bd312ad91a",
>>> #   "projectId": "21425d1a-70f9-4bke-8140-81bd312bd91b",
>>> #   "role": "owner",
>>> #   "createdAt": "2024-03-20T09:32:03.565075+03:00",
>>> #   "updatedAt": "2024-03-20T09:32:03.565075+03:00",
>>> #   "projectName": "[DEMO] EV",  

Пример использования REPEAT VISION в дистрибутиве, установленного по локальному адресу "https://my.repeat.vision.local", в котором публичный REST API расположен по пути "/api/v1/public"

>>> from repeat import User, Application
>>> 
>>> user = User( token = "уникальный токен из кабинета пользователя дистрибутива REPEAT VISION")
>>> app = Application(
>>>     user, 
>>>     address = "https://my.repeat.vision.local",
>>>     common_path = "/api/v1/public"
>>>     )
get_exploration_model(project: str | int, time_interval: pydantic.dataclasses.dataclass = None, solver_retry_delay: float = 0.25, max_retries_number: int = 0) → ExplorationModel#

The method returns an instance of the :py:class:ExplorationModel class for further interaction with the REPEAT VISION model, ensuring the transfer of parameters to the model and obtaining calculation results.

Parameters:
projectstr | int

Unique identifier of a project with the REPEAT VISION model.

Hint

The project number is available in the REPEAT application on the project management page https://app.repeat.vision/projects. The project number is also available after opening (for editing or running) in the project settings in the id field.

time_intervalrepeat.data_structures.TimeInterval

Class to describe the time interval. Units of measurement None.

solver_retry_delayfloat | int

The number of seconds for each calculation delay. The default value is 0.25 [s]. This parameter, as well as the max_retries_number argument, are required in the following cases:

  • The number of users running models for calculation exceeds the available number of calculation modules. In this case, calculation cycles are allowed to wait for a free calculation module;

  • Conducting parametric studies, solving optimization problems, or running calculation cycles in the REPEAT VISION platform distribution on a local enterprise network with a limited number of available calculation modules. In this case, a calculation cycle may begin without even one available calculation module.

Added in version 1.1.0.

max_retries_numberint

The number of calculation delay attempts. If the value is greater than zero, a check is performed to see if a free calculation module is available. The default value is 0.

Added in version 1.1.0.

Returns:
modelExplorationModel

An instance of the :py:class:ExplorationModel class for further interaction with the REPEAT VISION model.

Examples

>>> from repeat import User, Application, TimeInterval
>>>  
>>> user = User(token = "уникальный токен из кабинета пользователя REPEAT VISION")
>>> app = Application(user)
>>> t_interval = TimeInterval(start = 1, end = 2500)
>>> project = "21425d1a-70f9-4bke-8140-81bd312bd91b"
>>> model = app.get_exploration_model(project, t_interval)
>>> print(model)
>>> # ExplorationModel(project = '21425d1a-70f9-4bke-8140-81bd312bd91b', 
>>> #                  name = 'Подготовка модели для автоматизации', 
>>> #                  time_interval = TimeInterval(start = 0, end = 1000))
get_model(time_interval: pydantic.dataclasses.dataclass) → Model#

The method returns Model class instance for further obtaining calculation results from REPEAT VISION model

Deprecated since version 2.0.0: You must use the :py:class:ExplorationModel class to interact with the REPEAT VISION model.

Parameters:
time_intervalrepeat.data_structures.TimeInterval

Class to describe the time interval.

Returns:
Model

Instance for further obtaining calculation results from REPEAT VISION model.

Notes

It is required to pre-start REPEAT VISION model and pause the model at the right time to further analyze the results using Model class instance.

Examples

>>> from repeat import User, Application, TimeInterval
>>>  
>>> user = User(token = 'уникальный токен из кабинета пользователя REPEAT VISION')
>>> app = Application(user)
>>> t_interval = TimeInterval(start = 1, end = 2500)
>>> model = app.get_model(t_interval)
get_projects(to_pandas=False, verbose=True)#

The method returns information about the user’s projects.

Added in version 1.2.0.

Parameters:
to_pandasbool

Flag for selecting the data structure in which to return the list of projects. The default value is False, which returns a dictionary.

verbose: bool

Flag for selecting the number of properties stored in the data structure. The default value is True, which stores all properties for each project. If False, only the name and project ID are stored for each project.

Returns:
dict[str | int, dict] | pd.Series | pd.DataFrame

Project information. Key is the project ID, value is the project properties REPEAT VISION

Examples

>>> import repeat as rp
>>> 
>>> user = rp.User(token = "уникальный ключ из кабинета пользователя REPEAT VISION")
>>> app = rp.Application(user)
>>> projects = app.get_projects(to_pandas = False, verbose = True)
>>> print(projects)
>>> # {"21425d1a-70f9-4bke-8140-81bd312bd91b": {
>>> #   "userId": "11125d1a-70f9-5bke-5145-81bd312ad91a",
>>> #   "projectId": "21425d1a-70f9-4bke-8140-81bd312bd91b",
>>> #   "role": "owner",
>>> #   "createdAt": "2024-03-20T09:32:03.565075+03:00",
>>> #   "updatedAt": "2024-03-20T09:32:03.565075+03:00",
>>> #   "projectName": "[DEMO] EV",    
>>> project_names = app.get_projects(to_pandas = True, verbose = False)
>>> print(project_names.head(2))
>>> # 21425d1a-70f9-4bke-8140-81bd312bd91b                        [DEMO] EV
>>> # bb18efd5-52b7-4d78-bk12-734653g77b45   DEMO] ТАД подъемного механизма
class repeat.repeat_model.ExplorationModel(project: str | int, name: str, time_interval: pydantic.dataclasses.dataclass, endpoints: _ApplicationEndpoints, solver_retry_delay: float = 0.25, max_retries_number: int = 0)#

Class for interaction with REPEAT VISION model.

The class ensures:

  • Transfer of input data to the model via REPEAT VISION global model variables

  • Start the model for calculation

  • Getting calculation results from blocks of Output port of External models library

  • Obtaining the necessary information about the model and calculation process

Parameters:
projectstr | int

Project ID. The project number is available in the repeat module via the projects attribute on the :py:class:Application class instance.

Hint

The project number is available in the REPEAT application on the project management page https://app.repeat.vision/projects. The project number is also available after opening (for editing or running) in the project settings in the id field.

namestr

Project name with REPEAT VISION model

time_intervalrepeat.data_structures.TimeInterval

Class instance to describe the time interval. Units of measurement None.

endpoints_ApplicationEndpoints

Class instance with attributes WEB API REPEAT VISION

solver_retry_delayfloat | int

The number of seconds for each calculation delay. The default value is 0.25 [s]. This parameter, as well as the max_retries_number argument, are required in the following cases:

  • The number of users running models for calculation exceeds the available number of calculation modules. In this case, calculation cycles are allowed to wait for a free calculation module;

  • Conducting parametric studies, solving optimization problems, or running calculation cycles in the REPEAT VISION platform distribution on an enterprise’s local network with a limited number of available calculation modules. In this case, a calculation cycle may begin without even one available calculation module.

Added in version 1.1.0.

max_retries_numberint

The number of attempts to delay calculation. If the value is greater than zero, a check for a free calculation module is performed before performing the calculation using the .run() method. The default value is 0.

Added in version 1.1.0.

Attributes:
custom_named_result_idsdict

Dictionary with results parameters containing custom names, Output Port blocks from the External Models library. The dictionary is available after starting model calculation by .run() method

parametersdict

Dictionary with model parameters. Key : str of dictionary parameters - REPEAT VISION model blocks identifiers. Value : dict of dictionary parameters - set of block parameters. The parameters dictionary is available after starting model calculation by .run() method

Returns:
None

Notes

In order to ensure that Python programs interact with REPEAT VISION model, it is required to have global variables in the model associated with the block properties you need. The REPEAT VISION model global variables are recorded with parameter values and boundary conditions from your Python program using ExplorationModel class instance.

Examples

>>> import pandas as pd
>>> from repeat import User, Application, TimeInterval
>>>  
>>> user = User(token = 'уникальный токен из кабинета пользователя REPEAT VISION')
>>> app = Application(user)
>>> t_interval = TimeInterval(start = 1, end = 2500)
>>> project = "21425d1a-70f9-4bke-8140-81bd312bd91b"
>>> model = app.get_exploration_model(project, t_interval)  
>>> variables = pd.Series({'pressure' : 85000}, dtype = float)
>>> with model as md:
>>>     md.run(variables)
>>>     results = md.get_results('flowrate')
property existing_variables: pandas.Series#

Attributes are based on model usage REPEAT VISION

Returns:
pandas.Series

Names of REPEAT VISION model global variables, as well as current values of variables with float type. Variable names are written in index attribute

Raises:
REPEATHTTPError

An error that occurs when it is impossible to obtain variable values.

REPEATVariableNotExistError

The error occurs when there are no global variables in the model.

Examples

>>> from repeat import User, Application, TimeInterval
>>>  
>>> user = User(token = 'уникальный токен из кабинета пользователя REPEAT VISION')
>>> app = Application(user)
>>> t_interval = TimeInterval(start = 1, end = 2500)
>>> project = 1247
>>> model = app.get_exploration_model(project, t_interval)  
>>> print(model.existing_variables)
>>> # pressure    70000.0
>>> # dtype: float64
get_all_parameters() → dict#

The function returns all available information about parameters of REPEAT VISION model blocks

Returns:
parametersdict

Dictionary with model parameters. Key : str of dictionary parameters - REPEAT VISION model blocks identifiers. Value : dict of dictionary parameters - set of block parameters.

Notes

The method works after the model calculation is started using the :py:meth:run method.

get_results(name: str, time_interval: pydantic.dataclasses.dataclass = None) → pandas.Series#

Method for obtaining calculation results

Parameters:
namestr

The name of the parameter for which calculation results are required.

Tip

The parameter name for which the calculation results are required. It is recommended that REPEAT VISION models use the Output Port blocks of the External Models library by setting up custom names in the Output Port blocks. It is also allowed to use parameter id from REPEAT VISION model block properties for parameter names.

time_intervalrepeat.data_structures.TimeInterval

An instance of a class to describe a time interval. Default valueNone in case time_interval was created during instance initialization of the ExplorationModel class and if for all result parameters a general time interval setting is sufficient. Use a new instance of the TimeInterval class as an argument to the time_interval method get_results() in case each result parameter requires own time interval.

Important

If the time_interval argument is different from None in get_results() method, the time_interval is used in priority instead of the ExplorationModel class instance attribute when creating the calculation result time series (Pay attention to the examples below).

Added in version 0.9.0.

Returns:
resultspandas.Series

Calculation results as a time series for a preset time_interval when creating Model class instance. The attribute name in pandas.Series will have a value according to parameter name specified as an argument to the get_results(name : str) method

Notes

Calculation results are available immediately after the first calculation iterations have successfully completed during the simulation process, after the model has been launched using the :py:meth:run method. The :py:meth:release_model() method clears the calculation results and terminates the calculation module.

Examples

>>> import pandas as pd
>>> from repeat import User, Application, TimeInterval
>>>  
>>> user = User(token = 'уникальный токен из кабинета пользователя REPEAT VISION')
>>> app = Application(user)
>>> model = app.get_exploration_model(
>>>     project = "21425d1a-70f9-4bke-8140-81bd312bd91b"
>>>     )
>>> variables = pd.Series({'pressure' : 85000}, dtype = float)
>>> with model as md:
>>>     md.run(variables, 
>>>            real_time_sync = False, # Синхронизация выключена
>>>            modeling_time = 2.5, # Секунды
>>>            integration_step = 100, # Миллисекунды
>>>            discretization_step = 100, # Миллисекунды
>>>            )
>>>     flow = md.get_results('flowrate',
>>>                           TimeInterval(start = 1, end = 2500)
>>>                            )
>>>     temp = md.get_results('temprature',
>>>                           TimeInterval(start = 2450, end = 2500)
>>>                            )
>>> 
>>> pipe_model = app.get_exploration_model(
>>>     project = "21425d1a-70f9-4bke-8140-81bd312bd91b", 
>>>     # Общий интервал времени
>>>     time_interval = TimeInterval(start = 1, end = 1000) 
>>>     )
>>> pipe_vars = pd.Series({'inner_diameter' : 0.2})
>>> with pipe_model as md:
>>>     md.run(pipe_vars)
>>>     # Расчётные значения расхода и давления необходимы для одинакового
>>>     # интервала всего времени моделирования
>>>     flow = md.get_results('flowrate')  
>>>     press = md.get_results('pressure')
>>>     # Температура нужна только для интервала времени при завершении 
>>>     # моделирования
>>>     temp = md.get_results('temprature',
>>>                           TimeInterval(start = 950, end = 1000)
>>>                           )
property log#

Log attribute describing the model calculation process

Returns:
dict

A dictionary with a log.

Raises:
REPEATHTTPError

If it is impossible to obtain the log.

release_model()#

A method to complete work with the model. The calculation is stopped, calculation results are cleared and the solver is stopped.

Returns:
None.

Notes

The .release_model() method is used when working with the ExplorationModel class using the with context manager. This approach provides:

  • Safe termination of REPEAT VISION model calculation process

  • The ability to set new values ​​for model variables the next time the model is run using the :py:meth:run method.

run(variables: pandas.Series, real_time_sync: bool = False, modeling_time: int = None, integration_step: int = None, discretization_step: int = None)#

REPEAT VISION model calculation start method with initial data transfer to the model. It is possible to transfer initial data values for global variables preset in REPEAT VISION model to the model.

Parameters:
variablespd.Series

The values of REPEAT VISION model global variables. Variables are generated in pandas.Series data structure, where index shall contain global variable names with str type, data type of variable values shall be dtype = float. For example, variables = pd.Series(data = [25], index = ['Temperature'],dtype = float)

real_time_syncbool

Synchronization with real time. Synchronization is disabled by default, value False. When synchronization is turned off, the calculation will be produced as fast as possible and usually ahead of real time. When synchronization is enabled, one model time step will approximately correspond to one real time step. When In large volumes of calculations, model time may lag behind real time.

Added in version 0.9.0.

modeling_timeint

The value of the simulation time (seconds), after which the calculation will be stopped. Defaults to None, uses model setting, set via the graphical application REPEAT VISION.

Added in version 0.9.0.

integration_stepint

The value of the integration step (milliseconds) between adjacent calculated model states. Default value is None, the model setting specified through the graphical application is used REPEAT VISION.

Added in version 0.9.0.

discretization_stepint

The value of the time step (milliseconds) between the nearest entries calculation results to the database. Default value is None, the model setting specified through the graphical application is used REPEAT VISION.

Added in version 0.9.0.

Returns:
None.

Notes

If you need to use the simulation time settings, stepintegration or time step between the nearest entries of results calculations to the database, then the .run() method needs to be passed the values ​​of the three required arguments: modeling_time, integration_step and discretization_step. Otherwise the values arguments modeling_time, integration_step and discretization_step are used from a previously saved REPEAT VISION model (see example).

Examples

>>> import pandas as pd
>>> from repeat import User, Application, TimeInterval
>>>  
>>> user = User(token = 'уникальный токен из кабинета пользователя REPEAT VISION')
>>> app = Application(user)
>>> t_interval = TimeInterval(start = 1, end = 2500)
>>> project = "21425d1a-70f9-4bke-8140-81bd312bd91b"
>>> model = app.get_exploration_model(project, t_interval)  
>>> variables = pd.Series({'pressure' : 85000}, dtype = float)
>>> with model as md:
>>>     md.run(variables, 
>>>            real_time_sync = False, # Синхронизация выключена
>>>            modeling_time = 2.5, # Секунды
>>>            integration_step = 100, # Миллисекунды
>>>            discretization_step = 100, # Миллисекунды
>>>            )
>>>     results = md.get_results('flowrate')
>>> 
>>> # Настройки времени modeling_time и шагов integration_step и 
>>> # discretization_step используются из модели, ранее сохранённой в 
>>> # приложении REPEAT VISION
>>> with model as md:
>>>     md.run(variables) 
>>>     results = md.get_results('flowrate')
property status: SolvingStatus#

Attribute of the state of the model calculation process

Returns:
model_statusSolvingStatus

Model status code, according to the :py:class:SolvingStatus class description: the model is in the process of being calculated or the calculation has been successfully completed. Once the calculation is successfully completed, the calculation result can be obtained.

Raises:
REPEATSolverNotRunError

If the calculation needs to be started or restarted.

REPEATSolverError

If there is an unknown error code or if RAM memory or permanent model storage memory limits are exceeded.

NotImplementedError

There is no implementation of repeat module operation for a model containing PAUSE or STOP blocks.

stop()#

The calculation stopping method with an option to download calculation results

Returns:
None.
class repeat.repeat_model.Model(user, solver: Solver, time_interval: pydantic.dataclasses.dataclass)#

Interaction class with REPEAT model to get calculation results

Deprecated since version 2.0.0: You must use the :py:class:ExplorationModel class to interact with the REPEAT model.

Parameters:
userUser

Instance of User class

solverSolver

Instance of Solver class

time_intervalTimeInterval

Instance of TimeInterval class

Returns:
None

Notes

It is required to pre-start REPEAT model and pause the model at the right time to further analyze the results using Model class instance.

Examples

>>> user = User(token = 'уникальный токен из кабинета пользователя REPEAT')
>>> app = Application(user)
>>> t_interval = TimeInterval(start = 1, end = 2050) 
>>> model = app.get_model(t_interval)
>>> with model as md:
>>>     res1 = md.get_results('1687723033287_OUT_2')
>>>     res2 = md.get_results('1687722637724_OUT_3')
get_all_parameters()#

The function returns all available information about REPEAT model parameters

get_parameter(name: str) → pydantic.dataclasses.dataclass#

The method returns a parameter existing in REPEAT model.

Parameters:
namestr

Parameter name. The available parameter name can be viewed in parameters dictionary of Model class instance

Returns:
Parameter

Instance of Parameter class.

Raises:
REPEATParameterNotExistError

Error declared if parameter name is not present in REPEAT model parameters set.

get_results(name: str)#

The method returns results for the requested model parameter name

Parameters:
namestr

Parameter name.

Returns:
resultspd.Seris

Time series of parameter values in pandas.Series structure. Series indices are calculated time values between the start and end values of TimeInterval class instance

Raises:
REPEATParameterNotExistError

Error declared if parameter name is not present in REPEAT model parameters set.

class repeat.repeat_model.SolvingStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

States of REPEAT VISION model calculation process

Attributes:
IN_PROGRESSint

Calculation is in process. Value 1

COMPLETEint

The calculation is successfully completed according to simulation time set in the project. Value 21

STOP_BY_CONDITIONint

Calculation successfully completed by condition (STOP block instruction, etc.). Value 0

STOP_BY_USERint

The calculation is stopped by the user from graphical interface. Value 2

PAUSEDint

The calculation is stopped by PAUSE block. Value 3

MODEL_NOT_FOUNDint

The calculation failed to start. The calculation module did not find the project. Value 20

EXCEEDED_RAM_LIMITint

Calculation is not completed due to limited RAM memory. Value 51

EXCEEDED_STORAGE_LIMITint

Calculation is not completed due to memory limitations. Value 52

ERRORint

There was an error in the calculation process. Value 100