Package: protes
PROTESDescriptionMethodPROTES(PRobabilisticOptimizer withTEnsorSampling) for derivative-free optimization of the multidimensional arrays and discretized multivariate functions based on the tensor train (TT) format.InstallationTo use this package, please install manually first thepythonprogramming language of the version3.8or3.9, then, the package can be installed via pip:pipinstallprotes==0.3.6To ensure version stability, we recommend working in a virtual environment, as described in theworkflow.md. Also note thatrequirements.txtcontainsjax[cpu]; if you need the GPU version of thejax, please install it yourself.UsageLet's say we want to find the minimum of ad = 10dimensional array (tensor) that hasn = 5elements (indices) in each mode. Let an arbitrary tensor elementyrelated to the d-dimensional multi-indexiis defined by the functiony = f(i) = sum(i). In this case, the optimizer may be launched in the following way:importnumpyasnpfromprotesimportprotesf_batch=lambdaI:np.sum(I,axis=1)i_opt,y_opt=protes(f=f_batch,d=10,n=5,m=5.E+3,log=True)The functionf_batchtakes a set of multi-indicesI(jaxarray having a sizesamples x d) and returns a list (orjaxarray ornumpyarray) of the corresponding tensor values;mis is the computational budget (the allowed number of requested tensor elements). Returned valuesi_opt(jaxarray) andy_opt(float) are the found multi-index and the value in this multi-index for the approximate optimum (in our case, minimum, since the flagis_maxis not set) of the target tensor, respectively.The inputIcan be easily converted to anumpyarray if needed (i.e.,import numpy as np; I = np.array(I)), so you you can use the ordinarynumpyinside the taget function and do not use thejaxat all.Note that the code runs orders of magnitude faster if the tensor's mode size (n) is the same for all modes, as shown in the example above. If you need to optimize a tensor with discriminating mode sizes, then you should use the slowprotes_generalfunction (i.e.,from protes import protes_general). In this case, instead of two parametersdandn, one parameternshould be passed, which is a list of the lengthdcorresponding to the mode sizes in each dimension (all other parameters for the functionprotes_generalare the same as for the functionprotes, which are detailed in the next section).Please, see also thedemofolder, which contains several examples of using thePROTESmethod for real tasks (a simple demo can be run in the console with a commandpython demo/demo_func.pyandpython demo/demo_qubo.py).Parameters of theprotesfunctionMandatory arguments:f(function) - the target functionf(I), where inputIis a 2D jax array of the shape[samples, d](dis a number of dimensions of the function's input andsamplesis a batch size of requested multi-indices). The function should return 1D list or jax array or numpy array of the length equals tosamples(the values of the target function for all provided multi-indices, i.e., the values of the optimized tensor).d(int) - number of tensor dimensions.n(int) - mode size for each tensor's dimension.Optional arguments:m(int) - the number of allowed requests to the objective function (the default value isNone). If this parameter is not set, then the optimization process will continue until the objective function returnsNoneinstead of a list of values.k(int) - the batch size for optimization (the default value is100).k_top(int) - number of selected candidates in the batch (it should be< k; the default value is10).k_gd(int) - number of gradient lifting iterations for each batch (the default value is1. Please note that this value ensures the maximum performance of the method, however, for a number of problems, a more accurate result is obtained by increasing this parameter, for example to100).lr(float): learning rate for gradient lifting iterations (the default value is5.E-2. Please note that this value must be correlated with the parameterk_gd).r(int): TT-rank of the constructed probability TT-tensor (the default value is5. Please note that we have not yet found problems where changing this value would lead to an improvement in the result).seed(int): parameter for jax random generator (the default value is0).is_max(bool): if flag is set, then maximization rather than minimization will be performed.log(bool): if flag is set, then the information about the progress of the algorithm will be printed after each improvement of the optimization result and at the end of the algorithm's work. Not that this argument may be also a function, in this case it will be used instead of ordinaryprint.info(dict): optional dictionary, which will be filled with reference information about the process of the algorithm operation.P(list): optional initial probability tensor in the TT-format (represented as a list of jax arrays, where all non-edge TT-cores are merged into one array; see the function_generate_initialinprotes.pyfor details). If this parameter is not set, then a random initial TT-tensor will be generated. Note that this tensor will be changed inplace.Other arguments:there are also a few more arguments (not documented) that we use for special applications.NotesYou can use the outer cache for the values requested by the optimizer (that is, for each requested batch, check if any of the multi-indices have already been calculated), this can in some cases reduce the number of requests to the objective function. In this case, it is convenient not to set limits on the number of requests (parameterm), but instead, when the budget is exhausted (including the cache), return theNonevalue from the target function (f), in which case the optimization algorithm will be automatically terminated.For a number of tasks, performance can be improved by switching to increased precision in the representation of numbers injax; for this, at the beginning of the script, you should specify the code:importjaxjax.config.update('jax_enable_x64',True)If there is a GPU, thejaxoptimizer code will be automatically executed on it, however, the current version of the code works better on the CPU. To use CPU on a device with available GPU, you should specify the following code at the beginning of the executable script:importjaxjax.config.update('jax_platform_name','cpu')jax.default_device(jax.devices('cpu')[0]);AuthorsAnastasia BatshevaAndrei ChertkovGleb RyzhakovIvan OseledetsCitationIf you find our approach and/or code useful in your research, please consider citing:@article{batsheva2023protes,author={Batsheva, Anastasia and Chertkov, Andrei and Ryzhakov, Gleb and Oseledets, Ivan},year={2023},title={{PROTES}: {P}robabilistic optimization with tensor sampling},journal={Advances in Neural Information Processing Systems},url={https://arxiv.org/pdf/2301.12162.pdf}}✭ 🚂 The stars that you give toPROTES, motivate us to develop faster and add new interesting features to the code 😃LicenseIf you plan to use this software for commercial purposes, please contactIvan Oseledetsfor details. There are no restrictions on the use for scientific purposes when citing 😊