zenterix

310 Reputation

4 Badges

3 years, 97 days

MaplePrimes Activity


These are replies submitted by zenterix

@tomleslie No worries. 

I have an animation such that the size of the resultant .m file is 383 mb.  

The code that generated this file took about four minutes to run. But it seems the real bottleneck is the call to actually display the animation in Maple. This takes forever: like so long that I haven't seen it yet and I've been waiting for fifteen minutes, and decided to write this post.

UPDATE: I had an inefficient computation in a procedure that computed the average of a list of lists. The issue was that a list was being updated in a for loop. Changing it to an Array (which is mutable) seems to have solved the issue of the call to display (which still takes long waaaaay less time).

Also I've run out of memory a few times when trying to display these animations.
 

@dharr But if you just spin up a new worksheet without saving it and read the mpl file then currentDir seems like it will just be the system home directory.

I'd like to get the path to the mpl file programatically from within the mpl file.

Please have a look at the code in this repository.

Specifically the AnimationTest.mpl file. I created this repo for another question I posted here about saving animations to files. But the data for those animations was created partly by a numerical solution to a system of differential equations.

In the aforementioned file, there is a procedure called solveEqs which solves a system of differential equations. Each of the two equations has a random term in it. The solution I found for being able to provide dsolve with such random numbers on each iteration was a table that keeps as entries the times used by dsolve and as a value the corresponding random number.

@acer @tomleslie

I created a package in an .mpl file, saved it to an .mla file, and create a worksheet to show how the package is used.

This package is a slimmed down version of my real code, but I think it shows all the issues that I have asked about. 

Please find the code in this Github repo

Now I want to write a little about what is happening in that repo. AnimationTest.mpl file contains a package called AnimationTest.

The package exports two main things: an object called NumberGenerator and a procedure called animate. For the purposes of my current question about saving animations, the important export is animate.

animate

animate calls computeAverage, which returns a list of lists. This list of lists has Np rows and three columns and represents 3D points of a trajectory.

computeAverage

Uses Grid:-Map to parallelize calls to solveEqs, which solves a differential equation (returned by a procedure called diffEqs) using dsolve, and then performs some calculations on the result, returning a list of lists, called slist. The outer list has length Np, the inner lists have length 3. Each inner list is a 3D point, and the entire outer list represents a trajectory.

Then, computeAverage sums the outputs from the N runs and divides them by N. Thus we have an "average trajectory". That is, the return value of computeAverage is again a lists of lists representing a trajectory.

------------------

Back to animate, after obtaining the list of lists from computeAverage, we convert it to a Matrix which we call q1 and we pass this Matrix to the procedure computeAnimationData.

computeAnimationData

This procedure does exactly what was done in my previous (garbage) worksheet: it calls plot:-arrow and plot:-pointplot3d to get plot objects ptrail and parrow, plus the plot object of a sphere which is the result of calling plottools:-sphere.

------------------

At this point, we can either display the objects or save them to a file. As per acer's example, I am doing this by saving the data to a .m file. 

For this demonstration, at the end of animate I am both saving to a file and displaying in the worksheet.

It works very well and is what I wanted. 

@tomleslie Sorry about that. I am usually very, very precise, but somehow I feel that Maple allows me to make a lot of mistakes. Perhaps that is just a downside of the power of the symbolic computations that we can do in Maple.

Maple is great, but it's kind of nightmarish when it comes to being able to prototype something quickly that is error-free.  But yes, your version does have the intended result. Let me just thank you two tremendously for the help with this.

The last step would be to save the animation.

I used the commands acer used in your other comments to save to an .m file. I'm not sure about what an .m file is. But reading it worked like a charm.

Garbage is a bit of a strong word. After all, this example (your version) did solve all the issues I had (generating the animations, saving them, and reading them). I don't quite feel like I understand what exactly is happening all the time, but I guess I just have to keep learning about Maple.

PS: How do I run the animations in this editor like you and acer are doing?

@acer Let me come up with a more substantial example worksheet and a more detailed post. I'll post it in an hour or so.

Here is a worksheet exemplifying the issue I am encountering to display my animation using this new way that doesn't use animate: Animation_Test.mw

Here is a summary of what is done in that worksheet

- create a matrix of size 20x3 where each row represents the position of the tip of an arrow

- create a list with the results of calls to plot:-arrow passing in each row in the matrix

- create a list with the results of calls to plots:pointplot3d, representing the "trail" or "path" of the last windowSize points at which the arrow was

- plot the arrow individually; it works. Plot the trail individually; it works

- I'd like to plot both at the same time. My issue at this point is just the syntax of using display to accomplish this, as you can see in the worksheet. I've been trying various variations based on the examples you guys provided, to no avail yet.

- if I can do this, then it means I can save these lists to a file and read them in later and display.

@tomleslie okay, I get it. This looks very promising. I guess plots:-animation is just a wrapper around this very strategy, right?

I will implement this and let you know how it goes.

I am using plots:-animate. This returns a function which I pass to display (in reality I have five such functions animating different things, and they are all sent to display to get the final animation). How would you save such a function?

For a bit more context, the solution to the system of differential equations is a trajectory on the surface of a sphere. I also compute a window of the last N points in this trajectory so this is also animated. I also have another trajectory representing something else. These trajectories are the tips of arrows that start at the center of the sphere and they are also animated.

I managed to save one of the animations as a gif using Export, but did not manage to Import it yet.

UPDATE: I also managed to save an animation as a gif using plottools:-exportplot. I suppose I could save all five animations this way in a directory and then import them and display them. Not sure if this is smart or if there is a better way though.

UPDATE 2: But one of the things I want to save, the sphere, isn't an animation. It's just a call to plottools:-sphere which generates some result that when I print it out says MESH. Not sure what this is but I can't save it as a gif like for the animations.

@acer 

This works very well for, well, a Matrix (or a Vector with ExportVector). 

Truth be told, however, what I actually want to save is the result of calling plots:-animate. This is not a Matrix. The error I get when I try to save this thing is

Error, (in QComputing:-computeAndSaveAnimationData) invalid input: ExportMatrix expects its 2nd argument, M, to be of type {Matrix, list(Matrix)}, but received [PLOT3D(ANIMATE([CURVES(Matrix(1, 3, [[-0.,-0.,-1.]], datatype = float[8])), TITLE(t = 1.)],[CURVES(Matrix(2, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506]], datatype = float[8])), TITLE(t = 2.)],[CURVES(Matrix(3, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506],[-.003871386882,.03871964562,-.9992439148]], datatype = float[8])), TITLE(t = 3.)],[CURVES(Matrix(4, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506],[-.003871386882,.03871964562,-.9992439148],[-.008739819788,.05805870882,-.9982765367]], datatype = float[8])), TITLE(t = 4.)],[CURVES(Matrix(5, 3, [[-0.,-0.,-1.],[-.0009668681546,.01893805236,-.9998206506],[-.003871386882,.03871964562,-.9992439148],[-.008739819788,.05805870882,...

Looks like there are various Matrices inside this bit data structure.

Any idea how to save this?

In reality I have a sphere, and then four animations. The latter are two arrows from the center of the sphere to its surface, plus the path traced out by the tips of the arrows. 

Right now, I'm keeping the four results of calls to plots:-animate and the call to plottools:-sphere in a list and I call plots:-display to display them all together in one animation.

I'd like to generate the data for the entire thing (the list of five things), and save this. When I read the list, I just call display and pass the list.

@mmcdara 

I want to solve a system of differential equations that depends on a set of stochastic parameters. Basically, this means that every time I solve I will get a slightly diifferent solution.

In general terms, to accomplish this what I do is run a procedure using Grid package. 

The procedure contains the call to dsolve. I run the procedure N separate times using Grid package's Map procedure for parallelization. From each run I obtain an output which is essentially the result of dsolve.

Then I average them and plot them. This is all done in a worksheet.

I'd like to have this entire process be executed in a batch file. Ie, run the Grid:-Map command that I am using to run the procedure in a batch file, and each procedure saves its output to a file. Then later on (after the long time it takes to run the procedures), I can simply read the files and make the plots.

I think the specific application (solving this system of differential equations) is secondary to the main question I have which is: in general, what is the best way to save results of computations to be used later on in a different session or worksheet?

@acer How is this

"Side-note: You can also programatically create a self-installing file which unpacks any or all of .mla, .help, source, and build-scripts to the equivalent directory on someone else's machine. (This knows where to place these toolbox files regardless of operating system: Linux, MS-Windows, or OSX.)"

done by Maple?

@Joe Riel 

I'm used to big JavaScript projects with thousands of files and a variety of flavors of organizing those files.

I've asked here before about what people do to organize their files and to improve their workflow and productivity. I'm still converging on what my ultimate workflow in Maple will be, but my initial approach is to have each .mla file together with the other files that are associated with it. This way I can use .git and share with my collaborators.

The reason I want to modify libname programatically is so that I can create new projects and not have to manually change the initialization file.

I am aware that some keep all .mla files in one single location and this means they don't touch the initialization file. That's fine, I'm just trying a different way to see if it works.

The repository I linked seems to have a working package that does what I expect. In particular: add a path to libname in the initialization file, remove any path (by index) from the initialization file, and save a package contained in an .mpl file to an .mla file.

The workflow becomes:

1) create a new project directory (or clone a newly created github repo)

2) call addPathToLibname(projectDirectory) 

3) create one or more .mpl files that define packages

4) call savePackageToMla(mlaPath, mplPath, packageName)

5) use the saved package from any worksheet using with or use

6) after code for a package has been modified, call savePackageToMla(mlaPath, mplPath, packageName)

7) since the .mla file is part of the directory, someone else can clone the repo, call addPathToLibname(projectDirectory), and they can use the package in their worksheets

We need to use the option 'overwrite' with FileTools:-Open, as follows

FileTools:-Text:-Open(mapleInitFile, 'overwrite'):

I read about it here.

@acer I will try to be more careful to not post inaccurate commands that I am using. 
In fact, mplPath and mlaPath use double quotes, so no problem there.

I have to confess something. At this point, it does work but I am not sure anymore what the issue was.

1 2 3 4 5 6 Page 5 of 6