darkreactions/ESCALATE_Capture

Wolfram Integration

Closed this issue · 2 comments

I am having some trouble integrating the Mathematica code into ESCALATE.

Specifically, the code is failing from within Wolfram itself. Instead of returning a dictionary, it is returning a string representation of a Mathematica function, which it seems to do when its fed something it doesn't like. The problem is, I can't tell what I'm feeding it that is substantively different than the input it got in the attached IPython notebook.

More on this below.


I integrated the WLS file with the wrapper defined here:

class WolframSampler:

Forgive the gratuitous object orientation: my aim was to keep the WolframLanguageSession object out of the global scope but let it persist over time.

The method defined here:

def generateExperiments(self, reagentVectors, nExpt=96, maxMolarity=9., finalVolume=500.):

is intended to keep Wolfram from silently failing when passed ints instead of floats, which is a problem I had earlier. If you want, you can ignore this method for debugging purposes and instead use the private method defined here:

self._generateExperiments = self.session.function('generateExperiments')

which, notably, should work exactly the same as the function I defined in the IPython notebook (attached).


Sanity checks I have already performed:

  1. This line prints out the global scope in the Mathematica session. It should contain all of the functions that Josh defined, and as far as I can tell it does.
    print(self.session.evaluate(wlexpr('Names["Global`*"]')))
  2. I switched to using the private method WolframSampler._generateExperiments() discussed above, but I still get the error.
    experiments = ws._generateExperiments(reagent_vectors)

Moving forward:

The code as currently written prints a bunch of stuff you might want to see, including the dict of the vector representations of the reagents, and the Wolfram output. Attached is a zip containing the IPython notebook where the Mathematica code works. I would start debugging this by triple checking that I didn't do something that doesn't match the implementation in the notebook. As far as I can tell I haven't but, perhaps someone who isn't me will be able to catch my own subtle mistake.


Attachment:

wls_py_notebook.zip

Note: the output I'm getting from the code on my local is

Obtaining chemical information from Google Drive..

Functions defined in Wolfram session:
['allowedExperiments', 'allowedHull', 'compositionBoundary', 'compositionBoundary$', 'convertConcentrationsToVolumes', 'correctDimensionalityVector', 'correctDimensionalityVector$', 'd', 'd$', 'experiments', 'finalVolume', 'generateExperiments', 'hull', 'hull$', 'imposedBoundary', 'imposedBoundary$', 'maxConcentration', 'maxMolarity', 'minConcentration', 'nExpt', 'nExpts', 'processValues', 'reagentDefs', 'reagentNames', 'reagentNames$', 'reagents', 'sampleConcentrations', 'space', 'space$', 'stocks', 'stocks$', 'v', 'v$', 'x', '$MinVersionSupported', '$NotSupportedVersionErrNo']

Reagent vectors:
{'Reagent1 (ul)': [0, 0, 0],
 'Reagent2 (ul)': [2.85, 0, 2.28],
 'Reagent3 (ul)': [4.18, 0, 0]}

Wolfram output:
Times[500.0, Global`convertConcentrationsToVolumes[{'Reagent2 (ul)': [3, 0, 2], 'Reagent3 (ul)': [4, 0, 0], 'Reagent1 (ul)': [0, 0, 0]}, Round[Global`sampleConcentrations[BoundaryDiscretizeRegion[BooleanRegion[Function[And[Slot[1], Slot[2]]], [MeshRegion[[[2.85, 0.0, 2.28], [4.18, 0.0, 0.0], [0.0, 0.0, 0.0]], [Polygon[[[1, 2, 3]]]], Rule[Method, [Rule['EliminateUnusedCoordinates', True], Rule['DeleteDuplicateCoordinates', Automatic], Rule['DeleteDuplicateCells', Automatic], Rule['VertexAlias', Identity], Rule['CheckOrientation', Automatic], Rule['CoplanarityTolerance', Automatic], Rule['CheckIntersections', Automatic], Rule['BoundaryNesting', Automatic], Rule['SeparateBoundaries', Automatic], Rule['TJunction', Automatic], Rule['PropagateMarkers', True], Rule['ZeroTest', Automatic], Rule['Hash', 5359314806790543420]]]], Cuboid[[0, 0, 0], [9.0, 9.0, 9.0]]]]], 96]]]]

Patched with f4f0365. @ipendlet may still have to handle some domain reasoning problems that lead to the error, as discussed in Slack. I will leave the issue open until he confirms that those problems are handled.

@ipendlet feel free to close when you are ready.