Message Boards Message Boards

Differences between Mathematica on the desktop and the cloud?

Hi Everyone,

First off, I'm John and I just joined. I don't why it took so long and was only reminded about this when I heard about the 13,000 milestone being reached and I realized that I could post my question here and give Wolfram support a break. Anyway, I apologize if this question has been asked but here goes.

I recently struggled with something fairly simple and it comes down to the behavior being different on the desktop than in the cloud. In particular if you do RandomInteger[10] in the desktop, you potentially get a different pseudo random number each time you execute the cell.

Therefore I naively assumed that CloudDeploy[RandomInteger[10]] would behave the same way, but it doesn't, you just get a number and it doesn't change when you refresh the page. Eventually, I figured out that I needed to use Delayed as in CloudDeploy[Delayed[RandomInteger[10]]] in order to recover the same behavior as on the desktop.

My first question is to ask if this is a bug or by design. In either case I would appreciate an explanation for these different behaviors. Finally, in general I would like to know if there are any resources that address where wolfram cloud behavior differs from the desktop as it is usually the same but not always. Thanks.

John

POSTED BY: John Erickson
2 Replies

Hi David,

Thank you for the explanation. So you really can't just say, "Just wrap it in CloudDeploy and it will work!" as I had been telling myself since the normal evaluation rules still apply. Are there any guidelines or best practices for how one handles these situations? The question that troubled me was an expression like FormFunction[{ToString[RandomChoice[{a,b,c}]]->"String"},#&][]. This works as you would expect in the notebook producing pseudo random associations like <|"a" -> "1" |> (assuming you put in 1 as your input).

If you try wrapping this in Delayed at any level and then try and Deploy it to the cloud it fails. I found a rather insane workaround to all of this by changing my approach, but I am still wondering if there is anything that can be said in general on the order of if expr works in the the desktop then expr suitably modified will work in the cloud. I am just trying to avoid ad hoc hacky solutions if possible.

John

POSTED BY: John Erickson

This is because, before CloudDeploy is executed in

CloudDeploy[RandomInteger[10]]

The RandomInteger[10] is first executed, yielding an integer to be deployed. So what gets deployed to the cloud is the result of the execution of RandomInteger[10]. The Delayed function is specifically designed to help overcome this behavior in the Cloud.

So, not a bug.

POSTED BY: David Reiss
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