Package: dyrun
Dynamic Runner (DYRUN)This Python-based basement environment is designed for simulating dynamical systems, including differential equations, and visualizing their results, which can be particularly useful for academic research and paper presentations.dyrunis a simple tool that facilitates simulations expeditiously and effortlessly, using invaluable instruments for modeling linear and nonlinear dynamic systems. This formidable instrument is capable of executingdifferential mathematical equations[1] and is advantageous forControl engineering,Estimation[2, 3],Encryption[4],andNeuroscience[5, 6].Researchers who wish to delve into the realm of dynamic and control systems will find this package to be an invaluable resource.LicenseMIT licenseAuthorAbolfazl DelavarEmail: faryadell [at] gmail [dot] comWebpage:https://github.com/abolfazldelavar"Successful people are those who can build solid foundations with the bricks others throw at them."InstructionsInstallationTo install the full package, run the below code:pip install dyrunTo build a new project, just run the following order:dyrun DIR_NAMEIf the package has been installed, you can update it by:pip install --upgrade dyrunwhere theDIR_NAMEdenotes the folder you wish to create the project.First tryingThe main file of this package isdyrun.py, which can be run easily using:python3 dyrun.pyHowever, the jupyter format of that is also provided in order to have better control on each section of that.
It is recommended you to modifydyrun.ipynbfile to make the most of jupyter tools and facilities.
All sections will be introduced in the following.The structure ofdyrun.ipynbThe notebook is organized into the following sections:Introduction:,Requirements:,Custom Functions:,Parameters:,Signals:,Models:,Main:,Execution:,Illustration:, andPreservation:.The notebook is designed to be self-contained and easy to follow, even for users who are new to dynamic simulations and thedyrunlibrary.
The only effort you must make is to read the instruction presented indyrun.ipynband this guideline.IntroductionA brief overview of the *dyrun* library and its main features.RequirementsThe external dependencies utilized in the project are documented in this section.Custom FunctionsAny custom functions for the project are defined in this section.ParametersThis section establishes the static quantities such as model parameters used throughout the entire project.SignalsThis section is designated for the definition of any signals and array variables.ModelsDynamic objects and those that are not as elementary as an array must be included in this section.MainThis section contains the simulation function that is used to run the project.ExecutionThis section contains the code snippet to run the project.IllustrationThis section is used to display the results of the simulation.PreservationThis section is used to store data.RequirementsThe file namedcore/lib/required_libraries.pyis where the crucial requirements are loaded and used througout the project. You will not need it normally, unless you wish to use a specific library in the whole project. In other words, all addition requirements should be called in the requirements section ofdyrunfile. For instance, as long as the project needs to use a specific model file (This will be discussed in the following parts of this instrustion), they should be called byfrom blocks.general_blocks import *in this important section.LibrariesIn this section, all available libraries that can be utilized for better managing your projects are given.`Clib`This pre-imported library which you can find it in therequirementssection of thedyrun.ipynb, brings you several useful functions, which will be elaborated now:set_timer(ID): This function sets the timer and initializes the simulation. It also sets up the logging module, creates a log file in thelogsdirectory with the name<ID>.log, and writes a message to the log file indicating that the simulation has started.ID(input) - The id number of the simulation; it is usually unique.Output: The current time at the moment that the function is called.end_report(start_time): This function reports the end of the simulation and the time it took to run. It calculates the elapsed time since the simulation started, formats it as a string, and writes a message to the log file indicating that the simulation has ended and the elapsed time.start_time(input) - The time the simulation was started (returned byset_timer()).Output: None.get_now(report_type=0, splitter_char='_'): This function returns a string containing the current date and time in the specified format. The format of the output string depends on the value ofreport_typeandsplitter_char. The function gets the current date and time using thedatetime.now()method, formats it according to the specified format, and returns the formatted string.report_type(input, optional) - The type of report to generate. The default value is0.0: YMDHMS1: YMD_HMS2: Y_M_D_H_M_S3: YMD_HM4: YMD_HM5: Y_M_D6: H_M_Ssplitter_char(input, optional) - The character used to separate the different parts of the date and time. The default value is'_'.Output: A string containing the current date and time in the specified format.Certainly! Here are the revised instructions for theClibclass, which provides several useful functions related to file I/O. For each function, I've provided a brief description of its operation, along with the input variables and output variables:diary(message, no_print=False): This function is used to put the message in the diary file as well as to print it to the console. It writes the message to the log file using theloggingmodule and also prints the message to the console ifno_printisFalse.message(input) - The message that you want to show or put in the diary.no_print(input, optional) - A boolean value that specifies whether to disable printing to the console. The default value isFalse.Output: None.save_csv(tensor, name, zip=False): This function saves the given data in a.csvfile. IfzipisTrue, it creates a.zipfile with the same name as the.csvfile and saves it in the same directory.tensor(input) - The data that you want to save, e.g., matrices or numerical vectors.name(input) - The path including the name of the file where you want to save the data. For example,data/outputs/TensorFileName.zip(input, optional) - A boolean value that specifies whether to save the data as a.zipfile. The default value isFalse.Output: None.load_csv(name, maxsize=1000): This function loads the content of the given.csvfile saved bysave_cvs(). If the data file is too large, it can be restricted by specifying the maximum file size in MB using themaxsizeoption.name(input) - The path including the name of the.csvfile from which you want to load the data. For example,data/outputs/TensorFileName.maxsize(input, optional) - An integer value that specifies the maximum size of the file to be loaded in MB. The default value is1000.Output: The loaded data in the form of a NumPy array.save_npy(tensor, name, zip=False): This function saves the giventensoras a.npyfile with the specifiedname. Ifzip=True, the function saves the tensor as a.zipfile instead of a.npyfile.tensor(input) - The data to be saved, such as a matrix or numerical vector.name(input) - The path and name of the file to be saved, e.g.data/outputs/TensorFileName.zip(input, optional) - A boolean value that specifies whether to save the data as a.zipfile. The default value isFalse.Output: None.load_npy(name): This function loads the content of the given.npyfile with the specifiedname.name(input) - The path and name of the file to be loaded, e.g.data/outputs/TensorFileName.Output: The loaded tensor data.delayed(signal, k, delay_steps): This function creates a delayed version of a discrete signal.signal(input): The full signal.k(input): The current point in the signal.delay_steps(input): The amount of delay in integer steps.Output: The delayed signal value.sigmoid(time_line, bias, alph, area): This method generates a sigmoid function signal.time_line(input): The time line.bias(input): The time shift bias.alph(input): The smoother.area(input): The domain in the form of a list[a, b].Output: The output signal.exp_f(time_line, decay_rate, area): This method generates an exponential function signal.time_line(input): The time line.decay_rate(input): The decay rate.area(input): The domain in the form of a list[a, b].Output: The output signal.linear_mapping(x, current_area, target_area): This method linearly maps the inputxfrom the domain[a1, b1]to the range[a2, b2].x(input): The input array.current_area(input): The domain[a1, b1].target_area(input): Therange[a2, b2].Output: The output array.To use these functions, you can call them as static methods of theClibclass. For example, to save a tensor, you can callClib.save_npy(tensor, name), wheretensoris the data to be saved, andnameis the path and name of the file to be saved.`Plib`This pre-imported library which you can find it in therequirementssection of thedyrun.ipynb, provides several practical functions related to illustration purposes. The following methods are available:ThePlibclass provides several practical functions related to illustration purposes. The following methods are available:initialize(): This function initializes the environment and sets thefont.family,font.size, andtext.usetexto any further draws. Furthermore, the size of plot windows and several other essential properties are adjusted. There is no input to this function. Note that it is recommended to make sure the lastlatexpackage (likeTexLive) has been installed in your systems. you can download fromhere. It is used to draw for academic purposes. If you do not haveltex, you can temporarily ignore this function, although it is suggested to use it.Output: None.isi(params, fig = 0, save = False, width = 8.5, hw_ratio = 0.65): This function makes plots prettier and ready to use in academic purposes. The inputs to this function are:params(input): a string that describes the plot.fig(input, optional): the figure handler; useh = plt.figure(tight_layout=True)to create one.save(input, optional): a string that specifies the name of the file to save the illustration, or just insertTrue.width(input, optional): a float that represents the width of the figure in inches; default is8.5.hw_ratio(input, optional): a float that represents the height to width ratio between0and1; default is0.65.Output: None.save_figure(params, save=True, fig=plt.gcf(), dpi=300): This function can be used to save a figure/plot as an image file. The inputs to this function are:params(input): An object that contains various parameters related to the current run of the program.save(input, optional): A boolean or string value that specifies whether to save the figure or not. If a string value is provided, it is used as thefilenamefor the saved image.fig(input, optional): A matplotlib figure object that represents the current figure/plot to be saved.dpi(input, optional): An integer value that specifies the resolution of the saved image file in dots per inch.Output: None.linear_gradient(colors, locs, n=256, show=False): This function can be used to generate a linear gradient of colors. The inputs to this function are:colors(input): A list of color values in RGBA format. For example,[[1, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 1]]represents a gradient from red to white to black.locs(input): A list of values between 0 and 1 that specify the location of each color in the gradient.n(input, optional): An integer value that specifies the number of colors in the output gradient. Default value is256.show(input, optional): A boolean value that, if set to True, shows a plot of the generated gradient.Output: The output of this function is an array of colors that represents the generated gradient.cmap_maker(name, colors, n=256): This function can be used to create a Linear Segmented Color Map (LSCM) using the given colors and their locations. The inputs to this function are:name(input): A string that specifies the name of the color map.colors(input): A list of tuples where each tuple contains a value between 0 and 1 (specifying the location of the color on the graph line) and a color value in any valid format (e.g.,#FF0000for red).n(input, optional): An integer value that specifies the number of colors in the output color map. Default value is256.Output: The output of this function is a matplotlib colormap object that can be used for visualizations.To use these functions, you can call them as static methods of thePlibclass, similar toClib.`eclib`This is a Python library for numerical simulation of encrypted control.
    You have to import the library you need in the requirements section. For instance, to utilize `Paillier`, insert `import core.lib.eclib.paillier as pai` and use `pai` in the whole project.
    VisitEncryptedControl[4] for more information.A survey onScopeclass...QuestionsHow to model an LTI system?How to model a nonlinear system?How to model a network including nonlinear agents?References[1]. Butcher, John C. (2003). Numerical Methods for Ordinary Differential Equations. New York: John Wiley & Sons. ISBN 978-0-471-96758-3.[2]. Simon, Dan (2006). Optimal State Estimation. Hoboken, NJ: John Wiley & Sons. ISBN 978-0-471-70858-2.[3]. E. A. Wan and R. Van Der Merwe, "The unscented Kalman filter for nonlinear estimation," Proceedings of the IEEE 2000 Adaptive Systems for Signal Processing, Communications, and Control Symposium (Cat. No.00EX373), Lake Louise, AB, Canada, 2000, pp. 153-158, doi: 10.1109/ASSPCC.2000.882463.[4]. Teranishi K, Encrypted control library, github.https://github.com/KaoruTeranishi/EncryptedControl[5]. Izhikevich, E. M. (2003). Simple model of spiking neurons. IEEE Transactions on Neural Networks, 14(6), 1569-1572.[6]. Ullah, M., Fletcher, A. E. C., & Hake, J. (2006). The Role of Calcium Release-Activated Calcium Currents in Bursting Pacemaker Activity of Nucleus Ambiguus Neurons. Journal of Computational Neuroscience, 21(3), 271-282.