Failure to Understand sub-networks

Rory Creedon's Avatar

Rory Creedon

12 Mar, 2015 09:22 AM

I am fundamentally not understanding the process of grouping into sub networks. I understand the implicit looping and so on, but I just cannot make my sub networks behave as I want them to.

For example, I import a cvs file, do a series of lookups that returns a data object with 2 columns and 8 rows. I am only interested in the first four rows, so i use a slice node to get the first four rows only. But, when I group the lookups and the slice node together the slice node has no effect. All 8 rows are returned. So what do I do? Well naturally I group the lookups together into a sub-network and then slice the output. That works fine. But then when I group the slice together with the sub network, the same problem occurs.

What is it about sub-networks and looping that I am not understanding?

Sorry this is such a broad question. I have thoroughly read the docs and can't figure this last piece of the puzzle out...

R

  1. Support Staff 1 Posted by john on 13 Mar, 2015 10:44 PM

    john's Avatar

    Rory,

    I'm really glad you asked this question. This is the the number one most confusing, counterintuitive behavior in NodeBox I've encountered, and the tutorial on subnetworks makes no mention of it. I will share what I've puzzled out so far, but I hope someone from the NodeBox staff will give a more clear answer.

    Like you, my intuition is that simply encapsulating a group of nodes into a subnetwork should not change its behavior, but about 25% of the time it does. This behavior is tied to another poorly documented and well hidden feature: the port range setting inside the metadata dialog. Here is a magic trick it took me many painful weeks to discover...

    I recreated your example: an import_csv node hooked to a lookup node hooked to a slice node. The lookup node returns an 8-item list and the slice reduces that to 4 items. So far so good.

    I simply group the lookup and slice into a two-node subnetwork and surprise! Now I have 8 rows again as if the slice is not even there any more. Very strange.

    Here is the magic trick. Select your crippled subnetwork and click the Metadata button on top of the port pane. On the left you will see that your node has a single input port: list; click "list". A bunch of settings should now appear in the right half of the dialog. The fifth from the top, "Range", is set to "Value". Change it to "List" and Hit OK.

    Voila! Problem solved.

    For some reason (which I'm sure Frederik can explain), you need to tell your new subnetwork to accept a list, not a value. This seems odd to me given that the original Lookup node has, and still has, its list node set to Value. In fact, if you change the Lookup's list node to "List", before or after encapsulating it, it will stop working altogether. You have to change the network node metadata, not the nodes inside it. Why Value works for the Lookup but not for the network I do not understand.

    I have struggled with this but still do not fully grasp the difference between List and Value, and when you need to change it. A brief explanation of that would be a huge help to all of us struggling apprentice NodeBoxxers.

    John

  2. Support Staff 2 Posted by lucasnijs on 18 Mar, 2015 04:32 PM

    lucasnijs's Avatar

    Hello all,
    when you send a list to a subnetwork the subnetwork will do it's function for every item of that list. So it will generate always as many items as it is getting. A list will be treated on a one per one base, hence slicing it will return one item for every item since you are slicing a one item list every time.
    Now if you do not want this, i.e. you want your list to be treated as one item (containing a list of items for later slicing) you go to the metadata settings of your csv file and set the output to Value. Now your subnetwork will receive a Value (being a list!) and hence will return any slicing as expected since it is slicing a real list and not an item of a list. This way you can feed a subnetwork eventually with many lists (all considered as 1 item) and your subnetwork can treat them like that. I agree it may sound confusing, I struggled with it too...
    It also means that if you need the content of your csv file for other purposes you may have to import it a second time in another node where you leave the output to List.
    regards,

    Lucas

  3. 3 Posted by Rory Creedon on 19 Mar, 2015 07:43 AM

    Rory Creedon's Avatar

    Thanks John and Lucas,

    This is very useful. I think the List and Value system needs to be explained further, and how to control them needs to be clear. I encounter a problem in lack of understanding not just in relation to sub-networks, but also in relation to custom nodes. It is often much simpler to write my own python code to do stuff with data etc. rather than using a complex set of lookup nodes, and list indexing etc. becomes tricky when the arguments the function receives seems to change when grouped and so on.

    Thanks for your help

  4. 4 Posted by Rory Creedon on 19 Mar, 2015 09:36 AM

    Rory Creedon's Avatar

    Incidentally I just tried John's solution and it worked a charm. I think Lucas' one must also be correct, but presumably if it can be avoided then it should be, as using the same cvs data may then be tricky.

  5. Support Staff 5 Posted by john on 08 Jun, 2015 06:48 AM

    john's Avatar

    Even after this discussion I still found subnetworks confusing and have been tossing and turning ever since. I finally used a simple example to explore and explain the way they work in some detail.

    See the follow up note to my June 7, 2015 post on "Drop First Column" in the "Show Your Work" forum.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

25 May, 2024 11:52 AM
24 May, 2024 07:39 AM
16 May, 2024 02:11 AM
16 May, 2024 01:58 AM
14 May, 2024 01:29 AM

 

13 May, 2024 12:36 AM
12 May, 2024 07:46 PM
05 May, 2024 04:38 PM
03 May, 2024 06:50 AM
03 May, 2024 12:30 AM
03 May, 2024 12:09 AM