 This is Casper, I'm an electronic engineer and software developer and I use KeyCAD. If you want to grab these slides there's a lot of hyperlinks in here as well and you can anything I reference you can look up the slides and you'll be able to get to the thing I'm talking about. So I'm going to talk about experiment of sorts. It's probably not hugely useful yet but it's quite interesting I think and it's about defining PCBs as code and using code synthesis as an EDA tool. So it's kind of all started with KeyCAD and the file formats in KeyCAD, the text formats and like a lot of people they use KeyCAD I think I dove in and started editing things when the GUI wouldn't let me do what I wanted to do and while I was doing that you know I'd have my text editor on one side and KeyCAD on the other and I thought wouldn't it be nice if KeyCAD immediately refreshed the view when I edited it and I could see what I was doing in a more kind of interactive fashion and kind of in parallel I was interested in Haskell and I was learning Haskell and I wrote a parser and a writer for the KeyCAD footprint format in Haskell just because I had heard the S expressions are easy to pass and that could be a good learning exercise. So I wrote this and then I went kind of way overboard with the testing and I checked it against every footprint I could find and I used something called QuickCheck which is probably one of my favorite things about Haskell it's a property testing tool where you it will generate random test cases for you based on and then check them against your assertion so if you say something is true about your program it will generate random data and you know as long as you tell it to do it by default it will try a hundred times but you can tell it to do thousands of randomly generated data at your program to try and disprove your property your assertion which in the case of the parser and the writer because they're symmetrical is if I write out my KeyCAD expression and pass that again I should have the same expression so I do that with this tool as well but kind of back to S expressions because you know as I as I wrote this parser I learned more about them and how they actually you know quite they're not only easiest parser but actually a representation of the parse tree it's quite a simple representation and I learned more about Lisp and the schemes and kind of other languages that make use of this so I kind of stumbled across racket which is which is touted as a programmable programming language so what I found when I when I read up on Lisp is that there's a lot of there's quite a strong focus on macros and modifying the language and to your needs and defining new languages within the language because of the kind of ease that S expressions allowed with that S expressions allowed this you know for you to do this fairly easily but so in racket you kind of it has quite nice GI bindings as well so you know in the back of my mind I was thinking about my editor and what kind of editor I wanted to create so I was quite pleased that there's nice GTK bindings for racket and it has this IDE which is where you can interactively play with record code so when you start off with racket the first thing to say is I'm going to use the like racket language because that's not a pre-given thing if you're using racket so you can there's also something called a slideshow language I didn't use this for my presentation but you can interactively in the in the repo you can you can it has graphical output and uh there's quite a lot of different languages there's even an implementation of python so racket kind of took this idea of using macros and modifying the language to the extreme that you don't even need S expressions in your language anymore you can define other languages that don't use S expressions so there's a there's an implementation of python in racket um so I thought wouldn't it be neat if not only we have an editor where we can modify the the file format but we can also kind of mix in a programming language into into the into the format so having a language like a kycat language in racket and this is kind of how far I got with it I'd hope to make more progress on this before I gave this presentation but you know life kind of caught up with me and I'm giving another presentation next which is what I spend most of my time about open source hardware sharing platform but just about this so this is how far I got with it um so you can mix in this this general purpose programming language into the kycat format so if you look at fp line that's that's that's what the footprint format in kycat looks like and you can um here's a for loop that kind of it that outputs these fp line statements so you can kind of recurse arbitrarily deep into this and the end it will flatten it out and give you your kycat file back um so this is kind of what this is kind of what the code looks that's kind of how that works at the moment um there's a there's a syntax rule for the module which is the high level kind of this is my kycat module my footprint which is defined as a drawing of items and then we define the drawing what what it means to draw an item is to kind of execute all the functions that that item is defined as and flatten it completely so that you only have this this kind of flat kycat file and uh there's a little bit of uh just checking what layer this this footprint is on and kind of translating that to something within within the within the kycat within the record code here so this to clarify this is kind of what the source of what my editor looks like at the moment so this is kind of defining the the starts of defining a kycat language um so at the bottom I define an fp text item with again that's a kycat footprint expression really and I define it as a function that takes in the dc which is a drawing context and then executes functions on that drawing context so this is really I defined fp text as a as a drawing function um so I mean kind of before you get too excited about all of this is really early days for this I already mentioned I'd hope to make more progress on it and this is kind of this screenshot really shows what I've done in the best light possible as in this isn't I'm not using the right units the the line style isn't quite right yet you can't really do anything useful with this yet um but um just to jump ahead a bit um I had some more ideas surrounding this and it would be nice actually to if I managed to develop this further to use the the the graphical part so to do graphical manipulation or you know traditional mouse space manipulation or um um direct manipulation as well as the programming side to kind of to be able to intermix these two and I started thinking around this problem and I came across a project which is a quite a similar thing for svgs and you kind of you have this they have a special uh dsl for svgs and then they have their graphical part here and they've got done quite a lot of this is called sketching sketch I believe it's by someone called ravi chung and there it's in development as well and they've done quite a lot made quite a lot of progress and do some interesting things where where you where the where the kind of the graphical manipulate manipulation side um that generates the code for you that that that isn't just uh you know isn't just is readable still is readable still unusable and modifiable on the code side again but what I didn't find in sketching sketch it is um some way for you to generate loops like this and when I say loops really this is a kind of reversed map statement if you're into functional program it returns what's what what what the state the thing it defines it doesn't just you know execute side side effects um so I was I was I was thinking about this problem on how how can how can I get how would I get my editor to generate this kind of code for me and I and I came about and I I heard of the rosette language and I'd heard of like formal verification before and I always thought you well that's something that you know you do when you you're working on safety critical systems but I'd never heard the the term programming synthesis kind of with this as well which is what rosette advertisers and rosette is also a language in racket now what racket what rosette does is it connects racket up to smt solvers that's satisfiability modulio theory uh solvers which doesn't tell you much more if you don't know anything about it but um what what it essentially means is kind of similar to what uh I was doing with with with the haskill testing but instead of just you know picking up random you know generating random data it actually tries to exhaustively uh go and test every possible every possibility it's like an exhaustive testing tool now this doesn't sound it really doesn't sound possible and then you know if you ask me how do they how does this work it's very really very complicated because it's essentially an NP hard problem and there's a lot of interesting algorithms that go into that and that's kind of out of the scope of this talk by which I mean I don't know really um but there's a lot of smt solvers and this it's an active area of research and the one that that rosette uses is z3 which is actually written by microsoft um microsoft research and is mbt licensed um and so again rosette kind of hooks up the confused programmer which is you right there with a question mark um and and gives you uh lets you use rosette to generate uh to to do programming synthesis um and there's this is this is this is kind of the talk that got me into all of this and it's a very good talk and i'd recommend it for anyone interested in the subject and the links are in the slide but there's a bit a bit of a question if you you maybe you've understood now that it's an exhaustive checking tool the smt solvers are exhaustive checking tool but how can this be used for synthesis and uh really the way so far if i understand it correctly if anyone knows more about this feel free to interrupt me if i'm you know speaking nonsense but you pretty much give it a template of your desired construct so you could give it an empty for loop and you leave kind of the holes in there the question marks and um then you then you i've left the oh yeah no it's the next slide and then you can give it an assertion about your code so you would say i want to synthesize something that's the equivalent of if we go back um so this is trying to generate a pad at at a particular location kind of simplified uh kikad expression there and you could say i want this to be the equivalent of a pad at 01 and a pad at 02 and then you could with rosette uh and this assertion get a rosette and through back through the smt solver to give you the solution to that what kind of what kind of for loop construct is required to get this output here um i mean you might think that well that's a lot of complicated stuff that you'd have to learn to maybe make something that's not necessarily useful i mean i find it interesting i'm not i'm not sure footprints are necessarily the the the the the best application for this one of the most exciting things about all of this research is this is a feature in microsoft microsoft excel which is called flash fill and they use program exist this and it's from the same uh i believe the person that came up with this is was was studying with the same people that i keep linking in and this kind of from examples if we go back to if it goes when it loops back this out there you give an a an example and you say flash fill that and it tries to figure out what kind of transformation you wanted on on that data so it writes a little tiny program for you to do that transformation and it might get it it might say i don't know enough about what you've told me there to synthesize all that and if you give it another example it will be able to figure out what you wanted what kind of program you wanted to generate so that's my talk for now it's a little bit short but so there's uh quite a lot of time for comments suggestions questions yes this is a constrained solving and in constrained solving is used in eda in many areas for instance simple cases uh matching influence along the line with some transmission lines or can be seen as constrained solving problem and lay out itself just all the lay out is a huge uh constrained solving problem all right however it's usually done on the kind of low level if you can uh read the link back and can express for instance like uh you have an operational amplifier it's supposed to have an amplification of 10 whatever if you can express that logic somehow maybe using rocket or whatever now you can say like okay i have a i have a resistor value as well or like tell okay or i have a library of resistor values available locally it's generating the design which works given this uh this uh schematic right pressure uh so this is i think the very interesting aspects of yeah i think i think then there might be um that might be there might be more like i said there might be more interesting areas than for editing footprints i quite like uh using the footprint format because it's quite limited and i can i can it's kind of i can get somewhere quickly but yeah i'm sure there's more interesting applications uh any other yeah um well the the way i envision it to work is that um you write your you write you can write arbitrary code in here and actually if i ran this you could um you could go up here and say on the module and say kind of execute all of that and then you get your normal chi-cat uh pcb expression and then you can save that and you could you i'm not quite sure how how those two formats will will work out and what's that sir mac port are mad parts yes i have i have i have seen that yeah uh yeah yeah i mean chi-cat the the chi-cat reads this is the chi-cat footprint format i mean except for the for loop really so if here here's a here's a footprint this is what the chi-cat format looks like um so you just need to flatten it to get it into chi-cat yeah antenna design is one area where working with some higher level tools than uh manually doing out something that's very interesting yeah and the way people do it today usually you just find the book or something with the recipe how you do it so you don't in that you just avoid the general problem you just go through specific problems because there are some cases where uh that means that most antennas are very basic slinger antennas just ready in the direction because there's a known solve problem and you just change but in general if you can this requires a lot of and uh kind of domain understanding but if you express that you can generate i think this becomes very interesting when we go past pcb layout into the home conference subject so we currently doing then we're looking at say doing layout and tweeting so saying we're doing additive our paths are additive printer we don't have design tools that can do this in any good way so you can express the problem and even before that you have flex anyway today like your pcb is not maybe not going to remain flat on a on a surface or rigid so yes flex and uh multi i might want to use your walls as uh as you move these beams on what about those there yeah i've got i've got one yeah a little bit short it allows people to move in and out i mean you really enjoyed your talk really good especially like the high level of you it was good it was good really good for me okay you're there i hope that there will be more developer yeah i would keep meaning to i keep going out i keep like getting the source compiling it looking at it so it was good to have get a high level view how the thing is good yeah with that so the the example tool would that work for the both canvases then is that fine currently you know the this is for gal it's only for the for the gals oh gotcha because in the end we would like to have gals you know both in pcb new yeah yeah i feel that we have a very consistent way of fighting tools but that's not in five is it vivals still have legacy yeah i know they're both but um was it even on six get rid of legacy came with yeah probably six yeah that there are just a few things probably that we need to port from the legacy to the new canvas and after that we can try to drop it trying to think what i miss sometimes i switch back i don't remember why sometimes i think quick deleting there was shortcut i think my shortcuts are not transferred something or something oh yeah removing segments yeah i think you can do it with push and shove router when you have it enabled and then you cover over a track pretty easily which removes the whole connection but it's a bit different than the legacy so perhaps not many people really recognize that there is such option for that yeah i'm out of water hey now it's your turn my turn again yeah this is why i didn't wouldn't it be useful if you had for instance databases with commonly known ic's and and smd's uh where all the all the connections are known if you have the that database that you can extrapolate with the language those uh those footprints and that's could i get automatically generate from a from a database given from a from a manufacturer yeah i'm not sure this would have that much if you've got the if you've got the drawing if you if you've got the database and you've got the footprint this you wouldn't really need this the only thing is if you want to do parametric thing the other area is interesting if you if you look at like 3d card is they they do constraint based card do you say i want this to be here i want this to be here and then i think the the code synthesis and the constraint solving could be quite useful again like in free card for instance if you have a flange and you have put in 10 holes you're you're meant to diameter from the flange it either will disperse the holes if you have 10 holes over the the wider diameter yeah or it could be that if you fix the diameter to that he puts in two more holes yeah so that's parametric yeah that's uh that's about the gist of it that's cool i'm going to prepare my other presentation i'm so glad the internet's good with all the with all this clothes have you have you think i'm i can't the keyboard's not working the keyboard doesn't seem to be working oh i don't know it seems to be working i'm just doing it says that okay maybe in uh full screen mode it doesn't work i don't know what i don't know clothes on the open i don't know i've never actually played with these three so i i go for 20 minutes of speech and then five minutes of questions yeah so