Message Boards Message Boards

0
|
6333 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Running notebook with inputs from other Mathematica and MX files

Posted 3 years ago

I have a code in Mathematica file, which I want to run for large number of times (say 100) in series, and each time save o/p as *.MX file with the name "FileName_n.MX" ( where n is the number 1, 2, 3...100).

While running the file for 100 times, only two input parameters are different, say X and Y. For the nth run, X is a function of n, and Y is the o/p of the (n-1)th file. Would be thankful for any suggestion to perform this task. In a way, I want the main code file to take the values of X and Y from another files one by one, run the code and save the o/p with different names.

Of course, one method is the manual one, which I used for smaller number of runs. Where I created multiple files with different X values, imported the last o/p MX file and exported the o/p as MX file .. But this method is tedious for large number of files. Also, since o/p of each file is matrix of 6400X144 elements, I want to run each of the n files separately and have data stored in separate files. Thanks

POSTED BY: S G
3 Replies
Posted 3 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Kyle,

you want a notebook to script converter like jupyter has... yeah

Mark the cells in the notebook that you want to be exported as initialization cells. Then, "File / Save As" and select Format = "Wolfram Language Script"

POSTED BY: Rohit Namjoshi

Do you want to directly run your notebook? A "wolfram file" is ambiguous. You could set some global variables to change parameters and then iterate over NotebookEvaluate@NotebookObject[] where the object is found by running EvaluationNotebook[] in the notebook you want to run or by pointing at the file path. of the notebook you want to run many times. You could also save your notebook as a .wl script which you can run with commend line arguments. Or what I usually do when I have a notebook full of good cells is that I will move all the code into a big function definition so I can iterate over it. Or define each cell as a setdelayed variable by placing varName:= in the front. Honestly this refactoring process is a bit laborious. Ha, you know what the issue is, you want a notebook to script converter like jupyter has... yeah... Or you could also do some crazy madness using TemplateNotebook@NotebookRead@InputNotebook[] lol madness

POSTED BY: Kyle Keane
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract