# Import pytorch

**URL:** <https://forum.dynamobim.com/t/import-pytorch/40669>\
**Category:** Developers\
**Created:** [September 14, 2019, 8:47pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669 "2019-09-14T20:47:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![igpema](https://avatars.discourse-cdn.com/v4/letter/i/5e9695/32.png) [@igpema](https://forum.dynamobim.com/u/igpema)\
**Post date:** [September 14, 2019, 8:47pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/1 "2019-09-14T20:47:22Z")

</div>

Hello Dynamiters 😉  
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 🙂

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 14, 2019, 9:13pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/2 "2019-09-14T21:13:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![igpema](https://avatars.discourse-cdn.com/v4/letter/i/5e9695/32.png) [@igpema](https://forum.dynamobim.com/u/igpema)\
**Post date:** [September 16, 2019, 8:56am UTC](https://forum.dynamobim.com/t/import-pytorch/40669/3 "2019-09-16T08:56:13Z")

</div>

thanks!

---

<div class="post-metadata">

**Author:** ![Thomas\_Corrie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_corrie/32/63060_2.png) [@Thomas\_Corrie](https://forum.dynamobim.com/u/Thomas_Corrie)\
**Post date:** [September 16, 2019, 9:15am UTC](https://forum.dynamobim.com/t/import-pytorch/40669/4 "2019-09-16T09:15:51Z")

</div>

One workaround is to have a separate script running in Python 3 with PyTorch that is called from IronPython running within Dynamo using [subprocess](https://ironpython-test.readthedocs.io/en/latest/library/subprocess.html).

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.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 16, 2019, 2:17pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/5 "2019-09-16T14:17:32Z")

</div>

> [@Thomas\_Corrie](#):
>
> call Dynamo CLI headlessly from Python

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.

---

<div class="post-metadata">

**Author:** ![Thomas\_Corrie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_corrie/32/63060_2.png) [@Thomas\_Corrie](https://forum.dynamobim.com/u/Thomas_Corrie)\
**Post date:** [September 16, 2019, 2:50pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/6 "2019-09-16T14:50:31Z")

</div>

> [@jacob.small](#):
>
> 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.

A simple implementation in a separate Python 3 script using [subprocess](https://docs.python.org/3.6/library/subprocess.html#subprocess.run) is:

```
import subprocess
subprocess.Popen([
    'PathToDynamoSandbox/DynamoCoreRuntime2.2.1/DynamoCLI.exe', 
    '-o', 
    'PathToDYN/test.dyn'
]);

```

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](https://github.com/DynamoDS/Dynamo/wiki/Dynamo-Command-Line-Interface). 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!

---

<div class="post-metadata">

**Author:** ![igpema](https://avatars.discourse-cdn.com/v4/letter/i/5e9695/32.png) [@igpema](https://forum.dynamobim.com/u/igpema)\
**Post date:** [September 16, 2019, 3:05pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/7 "2019-09-16T15:05:49Z")

</div>

> [@Thomas\_Corrie](#):
>
> nished writing it!

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

---

<div class="post-metadata">

**Author:** ![Thomas\_Corrie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_corrie/32/63060_2.png) [@Thomas\_Corrie](https://forum.dynamobim.com/u/Thomas_Corrie)\
**Post date:** [September 16, 2019, 3:12pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/8 "2019-09-16T15:12:24Z")

</div>

I’m speaking during Session 3.4 on Saturday 12th (the last one of the last day) [https://www.dbeinstitute.org/event/bilt-europe-2019/schedule/](https://www.dbeinstitute.org/event/bilt-europe-2019/schedule/) Maybe see you there

---

<div class="post-metadata">

**Author:** ![Brendan\_Cassidy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/brendan_cassidy/32/7685_2.png) [@Brendan\_Cassidy](https://forum.dynamobim.com/u/Brendan_Cassidy)\
**Post date:** [September 16, 2019, 3:55pm UTC](https://forum.dynamobim.com/t/import-pytorch/40669/9 "2019-09-16T15:55:59Z")

</div>

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.

> **[mikaeldeity/Hackstreet-Boys](https://github.com/mikaeldeity/Hackstreet-Boys/tree/master)**
>
> Dynamo Hackaton best team. Contribute to mikaeldeity/Hackstreet-Boys development by creating an account on GitHub.

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.
