Although a perfectly understandable decision, it also means it wouldn’t be a trivial task to make and maintain a compiler for GH definitions. But perhaps GH 3.0 …
If comparing Gh definitions (not so strict) with UML diagrams (very strict) one of the big differences is just that, the strictness. And still not all attempts to roundtrip code and UML models has ended up being useful for “industrial strength” software development. But I do know of one example which actually delivers all the promises that surrounded UML in its heyday, and much much more. It’s called MDriven, and produces C# code (and even WPF forms from a form designer) among other things. Plus persistence (SQL databases).
MDriven is a hotted up C#.NET based version of the original industrial strength Bold Architecture (Win32) and includes an OCL expression evaluator so one can skip code-generation and directly execute the diagrams. A dream for concept studies and prototyping.
It would be a different product though. Swapping out the entire solver and data exchange mechanism for a different one is the hardest part. But GH2 has a bunch of performance improvements, so let’s see where that gets us. I’m hopeful that the new core design will make it easier to test different approaches like this, so it’s definitely something I’ll be coming back to once the basic product is up and running.
Ye, Sorry IVELIN, If this request at first look looks arrogant, insurmountable and rood or rude: English is not my first language. By the way, a genuine thanks for your contribution to this forum. I try to be polite, compact and I understand that this request is intrepid and cause a resounding reaction.
I’m grateful to Mcneel and this community that help me in my dream! I’m making a soaring simulator in C# Unity and using Rhino for modelling. Grasshopper for automation (I need to make a lot of gliders). I make this similar request to the game engine: (Programming in Commodor128 kb and now big builds? and they make it tiny. I wish to make the code in C# instead of UDK C++ and output in more optimising C++) and IL2CPP with toggles for 0 division check etc. They understand that and send me a grateful email about my contribution. They create a new compiler And is very useful! I’m not the author of the idea I just try to push for new ideas that help development. What is important is a healthy market at long terms or workflow in a way that is useful for all of us and future generations can learn to form it.
About resources and how to, I understand that Rhino market is not the same as Unity, but Unity was a good example of progress in this past 10 yr. Is free but if you make money you pay for it. A lot of code is property but open so as a user we try to fix it. I’m not complaining is just a business model example in the same sector to study.
Davide, I was thinking, for example, something like the Burst compiler that converts visual scripting (including loops) into the very best optimise strict possible. All this is just an idea to start thinking and I understand that the task is massive.
This sounds really hard and probably won’t give you the performance improvements you would hope for. It seems like we are optimizing a solution when we don’t understand the problem. If you share your definition, maybe we can look at it and figure out why it is running slow along with possible ways to improve performance.
Also I was thinking it seems like a band-aide solution, coding may take more time to learn than gh, but honestly once you know how to code, I find coding a component faster than creating a definition. I thought the point of GH was to make things easier for people who don’t have time to learn code or don’t want to be bothered with learning it. With ease you often sacrifice performance and that is just the way it is, but it seems David has some tricks up his sleeve for GH2.
Ok, I will share my definition in another thread. This topic is more like an idea for 5/10yr of development.
The problem is that we need Grasshopper to interact in real-time. If I make a quarter of a wheel and visualize the final result in realtime a mirror > polar array > merge > mesh > shader are all necessary and is slow. So I group into C# works well and is faster.
I need to do the same for a 150-foot sailboat with all the cables. walls, rig, etc. Grasshopper is so slow that I need a compiler. I can’t put it into a C# but can be automatic somehow.
Visual scripting is a much faster visual interface for visual content creation. Is like programming shaders in code or using visual scripting: visual scripting is better for that particular task. Because is an artist how is making the script. The compiler takes care to convert it into final better-optimised code. An engineer or a designer making surface and big 3D projects need visual scripting (better than “history”) because is a visual process. Not all task need visual scripting and I prefer coding in C#. But not for 3D objects or shaders. Looking at the graph helps a lot. Gh Visual scripting performance as C++ code. Ultimately hardware will catch up.
I imagine the hell of work it would require to create that (the compiler).
You also mentioned loops; standard GH doesn’t have loops functionalities, you need a plug-in.
So even every plug-in needs to be compatible with such “compiler” ? Bad idea.
… and not every GH logic “structure” can be converted into normal code. (it could, but sometime it would require re-interpretation or something like that… i’d say such compiler would pass the touring test… XD )
I think the best point is this:
… you can almost teach GH to people and make them using it without them knowing they are actually “programming”… GH is so easy that you can start build up some algorithm in a couple of minutes; that’s impossible with normal coding.
The only thing that popped in my head was “Neural Network for Code Generation”
@AlanMattano, I don’t think the performance issues you face in GH are actually GH problem. I think it is Rhino+Plugins problem. They all run in the same process. Another thing is GH relies on Rhino to do most calculations. If there was a safe (non-blocking) way to run Python engine sub-processes (or c# interpreter or whatever it is called that allows using C# as a scripting language) without blocking Grasshopper/Rhino then you would be able to hook-up (somehow) even UnrealEngine’s Cpp visual programming tool to Grasshopper and model your definition in UDK then compile it. Your hook in GH may even be just a single component.
You’re complicating yourselves (thinking of neural networks). It’s no use for an agent to learn how to optimize a task when you can’t know what the task is. How do you define the error function?
Isn’t that an architectural problem? GH has the functionality of the components within the components, rather than being defined separately. If they were separate, the methods used by the components on the one side and the components on the other side, the components would only be a shell, a wrapper (which even its generation can be automatic in the presence of these methods within the code); and then you could use those methods in other contexts such as from code, and if these methods are somehow identified (which should), it wouldn’t be much trouble to create a conversion from GH definitions to pure code that defines a new method, and also automatically create a component that calls that method. In short, if the functionality is independent of the ambale that needs GH to run, you can use the functionality without needing a GH document.
Node in code is useful when you want to use a single component from code, but it is useful for making the job easier. For definitions it is still better to create the definition from code using a virtual document (which is not assigned to the GH document editor I mean).
I also think that your problem is not going to be solved with this because there shouldn’t be a significant change in performance if you have a normal size definition and do the same thing in the same way but in other language. Your best bet is to optimize the definition bottlenecks, redefine the implementation, or optimize some subproblems parallelizing them from code, etc.
In cases of paintings created by an A.I. the jury that defines if the painting is good enough is also an A.I. Another agent is assigned to check if the colors are ordered properly and the blobs resemble a painting. One AI is learning to put pseudo-random colors, the other learns what is a painting by scanning existing ones.
I’m not an experienced programmer, but using the code provided by @piac, for compiling ghpython together with using reflection to figure out which component is connected to which, identifying also the name of the component in Node in Code. This “compiler” wish might as well be possible, in theory.
How could this be done with C# I cannot even dare to guess. C# is a mess.
The error function of an adversial generative network is well defined as if the discriminator considers a generated image real or fake. I don’t get the reason for the reference.
NodeInCode runs the components inside a GH document (even if not opened by the editor), because there is no other way to do it (I explained why before. Another solver could be created, but for what?). Then it should have a fairly similar performance to computing the components normally (GH is responsible for communicating data from one component to another), and in terms of performance, this is not the best way.
I meant this as a reference. I do not think zero-sum game plays any role there. The two AIs are not competing with each other, one is merely used to determine if the result is acceptable.
No one says it’s the best, just that it’s feasible. At least using IronPython.
Update:
On the other hand, you may be right about the AIs. there’s a loooot I have to learn.
I guess, it will gradually learn, crash/no-crash/compile/nocompile there must be some coding logic inside.
Are all components in the definition transformed into Node-in-code
are they connected (scan all inputs, outputs).
do type-check of inputs pass?
does rhino crash?
does the code compile?
I don’t know low level programming. I cannot completely answer the question.
as for ghpython compiling what do we know?:
you can scan the gh definition and find all components’ attributes (name, id, inputs, outputs, assembly)
having the above you can find them in node-in-code.
using reflection you can see if they are connected, and sort the list by the number of connected components to find the ones that have no gh-component input attached.
in reverse order connect them with node-in-code generating object’s names in progressive manner (alas, not very human readable)
after connecting them you can get the ones that have no connected inputs and create inputs of the ghpython component with their respective types. Similar for the output, you may pack the outputs to a single one.
I need to test to see first if this is possible with the limited knowledge that I have.
Well, it might learn the difference between compileable and non-compileable code, at least for the given test cases, but if it doesn’t know what the code is supposed to do it cannot verify it.
Also, these learning networks are useful if you want to take over some repetitive task which only needs to be correct N% of the time, but a compiler really needs to give you exactly what you asked for in ideally some time before next month.
I can see a use case for AI in compilers, which is the choosing between different implementations of provably the same logic, because then when the AI makes a mistake you only end up with a slightly slower runtime than you would otherwise. But none of that is even tangentially related to a GH compiler.
I think Ai can be useful inside Grasshopper C# component for creating new 3d objects (or removing noise). Unless memory management, for using Ai in the compiler can be early at the moment.
Instead, for the compiler, Unity clame x100 speed improvements over the existing “classic” MonoBehaviour architecture using better old school memory management allocation (nicer memory layout in the stack and the heap instead of a random layout).