Skip to content

Conversation

kasbah
Copy link
Contributor

@kasbah kasbah commented Jun 4, 2018

Just experimenting a bit with auto-orientation. So far only with resistors in the analog examples. It's a brute force approach, going through all the different combinations and I am trying to find a good metric. Everything just seems to favor complete vertical orientation so far.

image

Minimizing bendPoints seems like it could be a good metric and would allow for some horizontal components if it wasn't so awkward at placing them. E.g. for the common_emitter example this could be a total of 3 bendPoints (1 less than when both resistors are vertical) if the vin chain to the base of the transistor was straight:

image

@kasbah kasbah force-pushed the auto-orient-analog branch from 409ad4b to 3569f95 Compare June 4, 2018 18:39
@kasbah
Copy link
Contributor Author

kasbah commented Jun 4, 2018

I just found out about postCompaction and set it to 4 which I believe is LEFT_RIGHT_CONNECTION_LOCKING. All the strategies seem to improve all graph layouts in a similar way but I found some edges crossing a node in one case when using EDGE_LENGTH. Here is the common_emitter with the base resistor horizontal again. It doesn't actually impact the bendPoints count though. I guess those are not joined/removed.

image

@kasbah
Copy link
Contributor Author

kasbah commented Jun 4, 2018

I've implemented my own way of counting the bendPoints (ignoring any bendPoints that are on straight edges) and that seems to select good graphs. It's favoring having as many vertical resistors as possible while minimizing bendPoints. I also made it discount bendPoints that are going to output labels as that seems to help with the examples I have.

image

@dvc94ch
Copy link
Contributor

dvc94ch commented Jun 4, 2018

That invokes netlistsvg 2^(two-port) times. As I said I'm not sure all users prefer that to specifying the direction manually.

Is there a reason this can't be performed in replicad?

@kasbah
Copy link
Contributor Author

kasbah commented Jun 4, 2018

Yes, I am making no claims of great efficiency. It seems to at least be bearable for the examples. Nitpick: if added here it would invoke elkjs.layout 2^(n two-port components) times, and elkjs does seem to be pretty darn speedy.

Anyway, for the time being I am just playing around. If anything is added here it should be behind an option as to not impact other use cases. If it's better to put it into replicad then I'll put it there but there is nothing replicad specific at all to what I am doing.

postCompaction should definitely be the default as it improves all example layouts, I'll do a separate PR for that.

Just trying the mcu example.

before:

after:
image

@kasbah
Copy link
Contributor Author

kasbah commented Jun 5, 2018

@kasbah
Copy link
Contributor Author

kasbah commented Jun 5, 2018

@dvc94ch how did you get the pycircuit common_emitter to look like that in the readme?

When I run the example with current netlistsvg I get:

@dvc94ch
Copy link
Contributor

dvc94ch commented Jun 5, 2018

Not sure, not too many commits have been made, see which one caused the change... It still can be flackey sometimes even with the correct ports and orientations...

@kasbah
Copy link
Contributor Author

kasbah commented Jun 5, 2018

Ah thanks, yes, looks like it was the addition of lateral tags with f72ac93. What do you mean by flakey? Just a bit odd looking schematics sometimes?

@nturley
Copy link
Owner

nturley commented Jun 5, 2018

Whoa. Post compaction looks awesome! I need to try that. That might solve a lot of the issues with the ELK layouts that I was running into.

@nturley
Copy link
Owner

nturley commented Jun 5, 2018

This capacitor is backward.

image

Reverse it and it should look much better.

@kasbah
Copy link
Contributor Author

kasbah commented Jun 5, 2018

Not much better unfortunately.

@@ -19,16 +19,16 @@
         },
         "C2": {
           "connections": {
-            "A": [
+            "B": [
               70
             ],
-            "B": [
+            "A": [
               10
             ]
           },
           "port_directions": {
-            "A": "input",
-            "B": "output"
+            "B": "input",
+            "A": "output"
           },
           "type": "c_h"
         },

I would be interested to try and force input labels to be all the way to the left.

@kasbah kasbah force-pushed the auto-orient-analog branch from 30bdf66 to eafa8c5 Compare June 6, 2018 00:07
@kasbah
Copy link
Contributor Author

kasbah commented Jun 6, 2018

Rebased this onto #42 and it makes the mcu example almost perfect:

image

Full common emitter is better too, though you can see some of that weirdness mentioned in #42 going on in some variations.

image

@kasbah kasbah force-pushed the auto-orient-analog branch from eafa8c5 to 3a95d7e Compare June 8, 2018 16:44
@kasbah
Copy link
Contributor Author

kasbah commented Jun 13, 2018

Today I tried to feed it this Charlieplexing netlist.

image

It doesn't do so well with any orientation unfortunately.

image

@amstan
Copy link
Contributor

amstan commented Apr 13, 2019

For my circuits I found that the vertical capacitors works best. Most capacitors were decoupling, therefore one or both of the ends were going to a GND or a VCC. Horizontal capacitors were rare, the only places I can think of is:

  • series capacitors in filters
  • those AC coupling caps in the class A amplifier example

Similarly with resistors: pull-ups / pull-downs, if one or more pins on that resistor goes to GND or VCC, make it vertical. Though there are more places where I use horizontal resistors and regret them being so derpy due to lack of port swapping:

  • 0 ohm resistors connecting 2 signals
  • current measuring shunts
  • series termination

I'm not saying that auto orienting wouldn't be cool, but it's not the end of the world to not have it so far.

PS: Re #40 (comment)
The ideal would be for the diodes to be vertical and resistors to be horizontal. So ignoring auto orienting logic, does netlistsvg yield something compact? If not then your bend minimizing logic won't really detect this ideal orientation as optimal (so it shouldn't really be blamed).

@amstan
Copy link
Contributor

amstan commented Apr 13, 2019

Yep, the charlieplexing example looks pretty horrific even with directions hardcoded:

bad

After some port swapping (R3 was backwards, hooking up even numbered leds backwards since we don't support 180 rotation yet):

port_swapping

Looks a little better to me as a human, but there are a few bends in there, probably because of other elk layout choices, so I'm still not sure your bend metric would have picked this one above the first picture.

Regardless, I think the input to your combination trials shouldn't just be a matter of is it "_v" or "_h", you also need to consider the 180 deg rotation, that will essentially solve port swapping too.

@kasbah kasbah mentioned this pull request Sep 11, 2020
@kasbah kasbah marked this pull request as draft July 24, 2022 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants