Background
I have a fuction, which calculates an analytic solution to a multi-dimentional geometry problem.
The function takes a list of real numbers (typically less than a dozen) and outputs a list of reals of equal length (12 reals in -> 12 reals out). The function runs fast and doesn't require a lot of computational resources. More typical solutions to the problem involve statistical sampling of something like 10^5 points and use a substantial parallel computing infrastructure or lots of time. The idea has a number of commercial applications including epidemiology and insurance.
The function uses a number of "high-level" Mathematica functions including:
CholeskyDecomposition[]
IdentityMatrix[]
LinearSolve[]
Simplify[]
What I need
I need to deploy this function into a Windows based technology environment so that the users can call the function from some of their process workflows (e.g., they may call it from a database stored procedure or another program).
I need a deployment solution and have some concerns I need the solution to address, especially:
- keep the code proprietary;
- deploy reliable code; and
- make the function easy to use in the target environment.
The target environment does not include Mathematica; they have no other need to run Mathematica, CDF, or Wolfram Player Pro. They have no need or interest in running a Mathematica front end.
An ideal but likely unworkable solution
Generation of a C code executable would provide an ideal solution, but the function's use of the "high-level" Mathematica functions listed above excludes this as a simple option.
I'd consider developing my own versions of the high-level functions from lower-level Mathematica code that one could then compile to C code, but this just seems silly (and probably hard) If anyone has suggestions along these lines, thinks it possible, or can direct me to examples please let me know.
One can readily get C implementations of the Cholesky Decomposition, but that would introduce a whole other layer of complexity. Also, I never wrote much C code and what I did I did a very long time ago.
A workable solution?
Running the kernel and the code from a script file (without the frontend) seems like a place to start:
See: Mathematica Scripts
It looks like I can send parameters to a script. From the documentation on Script Parameters
...When running a Mathematica script, you may often want to modify the behavior of the script by specifying parameters on the command line. It is possible for the Mathematica code to access parameters passed to the Mathematica script via $ScriptCommandLine.
Promising, but the documentation does not provide a clear example of how I could call a Mathematica Script
with a list as a parameter. If anyone has suggestions on how to go about this or can refer me to information that gets me part of the way to a solution, please let me know.
Sidebar -- the tutorial makes no mention of running Mathematica Scripts under Windows. This has me a little worried. An answer to an earlier question I asked implies that one can do this on a Windows platform see: Chris' answer at the bottom. Does anyone know for certain? Examples appreciated.
Using Encode[]
seems like it could also help by securing the code and making it less likely that anyone could view it. This raises some questions:
The documentation for Encode[]
states:
On certain computer systems Encode["source","dest",MachineID->"ID"] can be used to generate an encoded file that can be read only on a computer with a particular $MachineID.
This would help a great deal in securing the code, but the documentation does not list the "...computer systems..." on which this will work. Any ideas?
More Encode[]
questions. Does one use Encode[]
to encode:
- single functions?
- notebooks including the function?
- packages (.m files)?
- something else?
The example in the documentation doesn't seem clear on this.
The beginning of a solution...
It seems like the following begins to give me a workable approach if I can clear up some of the issues:
- Use
Encode["source", "dest", MachineID->"ID"]
to secure the code. - Run the kernel(s) and the function from a
Mathematica Script
.
The target environment will need a Mathematica license and processes and policies to launch and shut down the kernels, but I can work with that.
Can I create a workflow wherein I:
- launch the kernel by a script at the begining of a day;
- use a script to call the function on the kernel throughout the day; and
- close the kernel at the end of the day?
This would help address the reliability issue.
Or should the kernel launch, run the function, then close everytime I want to use the function?
So...I've got a general idea of one way to go about this. I could use some guidance take it down another level of detail.
Oh, course if anyone has other ways to go about this, let me know.