Import pytorch

Hello Dynamiters :wink:
Does anybody know if we can import pytorch in Dynamo? I wanted to play with some GANS (Generative Adversarial Networks) and I dont know if someone did it already and if yes, great, just let me know :slight_smile:

Pytorch only works with Python 3, so it will not import into the Dynamo Python environment which is capped at 2.7.

It also May have issues running from a .net implementation.



One workaround is to have a separate script running in Python 3 with PyTorch that is called from IronPython running within Dynamo using subprocess.

The inverse, and the way I prefer to exploit the Python data science stack, is to call Dynamo CLI headlessly from Python 3. But this assumes Dynamo Sandbox rather than Dynamo for Revit in case you were using that.


This is interesting - do you have an example you can share as I am sure many could learn quite a bit from a simple file.

You may be able to leverage the Remember node from Refinery to ‘bind’ the requested Revit data into the dyn before you run the python bit. Wouldn’t help for a multiple rvt aggregator, but it could help for individual project stats.


A simple implementation in a separate Python 3 script using subprocess is:

import subprocess

This opens the specified dyn file using the chosen version of Sandbox, in this case, 2.2.1. The flags available are specified on GitHub. This one uses -o which instructs Dynamo to open headless and run a dyn file at this path

You can get it to output xml or json evaluations but I prefer to control the dataflow myself. My current workflow is to use Python to assemble a ‘job’ for Dynamo and write the variables to a json file. The dyn looks for this json when it is opened, it carries out the task and then writes the outputs I want to know to a different json file which Python then grabs the data from.

Most of the time I am running Python in a Jupyter notebook where it is even simpler because a preceding exclamation mark refers Jupyter to the command line:

!'PathToDynamoSandbox/DynamoCoreRuntime2.2.1/DynamoCLI.exe' -o 'PathToDYN/test.dyn'

Incidentally, I’ll be covering this at BiLT Europe session in a few weeks so there will be a more detailed handout once I’ve finished writing it!


nice, which day are you covering the Session in Edinburg? I was thinking of attending actually.

I’m speaking during Session 3.4 on Saturday 12th (the last one of the last day) Maybe see you there

You may want to dig through this repo because the hack street boys from the UK Dynamo hackathon implemented python 3 via c# into dynamo.

But if you are going to go the c# route you might as well look for native c# Generative Adversarial Networks instead of using python versions.