0:01Hi Jono. Nice to see you again.
0:04Hey everybody. Hey Jeremy.
0:06It's been another good week.
0:09What's been happening on the Discord? I've got something I can share, but do you want to start?
0:15Would you like to start recording before I do?
0:17No, I normally prefer to do it just a little bit too late. All right, welcome to lesson eight, I believe.
0:31Three to go. Yeah, it suddenly feels like we're right at the end. Um, so as always, I I wanted to start with a couple of um shows from the share it channel that uh students have been posting. I think Jeremy's got one as well. Yeah, this one was one I liked um more as a you should go and check out the dialogue and a related discussion from people discovering Demox. Um so that was a perfect example of just like using it as chat to learn something new
0:59while trying it out. Um but then the main piece that I wanted to highlight this is really cool. Here's my exploration. Um, the new trend that I noticed among a number of dialogues shared is people sharing dialogues that have some variant of, hey, this is my modification of so and so's dialogue, which is a modification of so- and so's dialogue. Feels like we're starting to get that little, um, organic evolution, you know, community piece going. Um, yeah, so this was one, um, building some tools to get YouTube transcripts. The other one I saw this
1:29was, um, uh, I think it was Matt. I spilled tea all over my notes, so I don't have the names today, but I'll share the links later. Um, yeah, I just had a list of like here's all the dialogues that he checked out once he'd done his version of the homework. Um, and so there's this like crosspollination of, oh, I liked the chat class and this and the approach here and this person's questions. Um, yeah. So, just more of that, please. I love seeing everyone um, building on each other's work.
1:53Can you scroll down the YouTube one a bit more? I was just curious to see it. Um, this one here.
2:00Yeah. Um, so it's you can see they've built it up in pieces in a separate dialogue. And so this one is more like here's all the code.
2:07Um, but um, the end result is using this tool. Um, so they have this add transcript from YouTube tool um, to take our lesson and it splits it into sections and it gives headings. Unfortunately, I don't know how to expand the collapsed sections in the preview.
2:22Yeah, you have to import them to do that.
2:24Yeah. So you'd have to import it into solver to actually see how it goes. But um yeah, nice to see you know what was that API Moonshot or something?
2:32I haven't seen that before. Do you see?
2:33Scroll down a little bit. Keep going. Keep going. Keep going.
2:37Moonshot is the Yeah, what a great idea.
2:43Um okay. And then apart from the it's wonderful that everyone's sharing the other one that I liked that I thought I'd feature was um the excellently named formalizer um by our friend Scott Hol, Dr. Scott Hol um which as you can see is a nice ambid project complete with source code and and docs page and so on. Um but they problem. Oh y let's do that.
3:08Um they have to write a lot of recommendation letters and then take exactly the text that they've just put into this lovely crafted letter and reenter it in pieces on various different web forms. Um, and so they've taken the ideas of playright and automation and uh, Claudette with tool loops and all these pieces that we've been showing um, and they put together something that will let you run this command to take your recommendation letter and to paste that into the
3:37appropriate forms but not submit. And so then you still get to review to make sure that it has extracted the right bits of information. Um, but yeah, I thought that was like a very good example of scratching a very personal itch with these tools to say, "Look, this is something I actually genuinely spend far too much of my time doing is writing recommendation letters for all of my students." Um, and so, yeah, Scott's gone and developed this full package to do this that I think he said even some of his colleagues are already like, "Oh, thank God you, you know, this is just what we've been dreaming about."
4:04Um, so yeah, really cool to see people just digging into, "Oh, I'd love to see a transcript of the YouTube video. I'd love to fill in these forms. I'd love to learn more about this new thing." and really getting the hang of doing those flows and solve it.
4:17Um, that's super cool. Uh, I'll show you one I saw that is also super cool. And I've already imported the dialogue. Um, thought it was super cool for a couple of reasons. Um, basically what this does, if I skip down a bit, is I'll just hit shift A to run all above. Um, is it creates a new magic JS2. So, there's already a percentjs in my Python.
4:54And JS2 is unique as far as I know in that it's a magic that takes this JavaScript, sends it to your browser, your browser computes the result and sends it back to solve it and then solve it puts it into your dialogue. Um, so you can see here it's creating functions, calling them, declare variables, use them in other messages. Um, and so this lets you do some pretty fun stuff. Um, we can create a canvas.
5:36So this is a canvas DOM element. So we can use show as usual. And so if you look at that, we've got here a canvas with an ID of particles. And um what they then did was they wrote uh a little demo that finds that canvas on the page and starts dumping stuff into it um each animation frame. And so if I run that wh There it is. Um
6:15so this uh is interesting because um literally for the first time I think now something exists in the world where you can get help on your client side JavaScript code you know mixed together with all the other stuff that solve it can do. um solve it won't be able to see the moving thing. Um but you can use the command shift so it can see normal outputs but it can't see the current state of the canvas. It just knows that
6:42there's a canvas element there. But you can of course say um command shift comma um and it can see the static image of the output.
7:11So, I had a little play with it to figure out how to cancel it. So, that was one thing it couldn't do before. So, turns out all you needed to do to cancel it, which I asked solv.
7:21Um, so then you can say cancel this. And I was also asking it playing around with getting it more concise. Apparently, we could get it down to that. Um, how does it work though was the bit that really interested me because uh you might remember Jonno last time I talked about our many stage process of refactoring uh capture screen you know and it wasn't really about refactoring capture screen
7:50it was really identifying that okay to capture a screen we have to interface JavaScript with solver it and I said look here's the early versions of that code. It's too long. And I said, I just don't think, well, I know for a fact people didn't do anything with it. Like, it was sitting there [clears throat] for six months. I can't remember. A really long time.
8:11Um and then we refactored it enough times and tried to name things carefully and got to a point where it's like oh we can provide something called push data that lets JavaScript push data to um uh to solve it and we can add a um event get that fires an event and passes in some data and reads any data pushed back. And so here that's what they've
8:39done. They've added an event listener. They've used push data. And so you can see the amount of code they needed to implement this. There's the JavaScript code. And there's the Python code. That's it. And you know, they've taken advantage of this as yet largely entirely undocumented thing. They figured out how it works.
9:01Um yeah, to create something that didn't previously exist in the world. So I thought that was a really good example of the value of you know building abstractions and naming them in a way that other people can can take advantage of it. So I was very impressed by this.
9:22Yeah. And also just great um work on the author's part to dig through the code and understand it to the point where they could implement that. That's a super useful um little piece of magic.
9:32Yeah, exactly. it actually they they do um mention in their dialogue they've got links to their um uh earlier um explorations. So I'll just click on those links and show you. It's nice that they've put it at the top here. This is like nice talking to your audience so that we can see the process.
9:52So um so a bit of research this is exactly the right thing for them to be looking at actually something I wrote. Um, so they were playing around learning about how magics work. So you can kind of see the process of [snorts] starting with like not knowing what to do and gradually finding things and experimenting with them. And you can see they're putting in little bits of code and seeing what happens and then okay. And so putting the goal
10:22at the top, very smart both for you and for the AI. Um thinking about possibilities and so using the AI as a bit of a chat partner. And again immediately though, try to get to code as soon as you can. Um and I'm not very happy that solve it does not know about the show function, but that's something we can teach it.
10:46Um, but it figured out a it figured out a way around it. So, you can always replace that with just show, by the way. Um, yeah. So, I thought that was really cool to to that they've shared their their learning journey across multiple dialogues.
11:03Yeah, I'm probably going to petition to get that into the solver demos folder as well. I really like that. Um, excellent. Okay. Well, that's our um featuring all the a subset of not all the great work. there's been lots more fantastic dialogues shared.
11:18In fact, I would say, you know, the community's just really exploded this week. You know, I just Yeah, with helpfulness and kindness and generosity and thoughtfulness, it's Yeah, it's amazing.
11:31Um, yeah, it almost feels a little bittersweet that the lessons will be ending, but the community won't be. So, we'll be sticking around and continuing to build.
11:41Um, fantastic. Okay, so Jeremy, the final two lessons, as we've told people, but just a reminder, um Eric Reese is going to be joining us and we'll be talking about um some very exciting topics with input from him. Um different ways of reading with Solit and writing. Uh reflections on what to do with your newfound skills or with your newly sharpened skills, I guess. Um lots of other um great sort of forward-looking pieces there.
12:08Getting access to his book for the first time.
12:10Oh, yes. Yeah. Yeah. Exactly.
12:14Preview version and um some cool ways to engage with that. Um but what we suddenly realized that meant is that today's lesson is the the last nonspecial Eric um episode. Um and so you'll probably have seen the YouTube title I think was something like um getting ready for advent of code and we'll talk a little bit about that. Um, but I thought it might be fun also to just kind of Yeah. I don't know. What did we think the lesson was going to be two days ago and then what do you think the lesson is today? And then what's the lesson actually going to be? Do you want
12:43to give us the the vague sort of agenda for today?
12:46Oh, sure. So, we will uh follow up on a couple of things from the last lesson. Um, so I ended up deciding that it's kind of been interesting, Jono, thinking about the teaching process. Originally I told you like I'm going to show people how to make a VPN and then I realized like no, that's not how I need to do things. I'll show people how to create my favorite kind of
13:14um virtual private server and then I'm going to make it a homework to make the VPN, which normally I would think is too difficult. Um, but with solve it, I actually think I should be doing this more often is taking people down the first half of a journey. Um, and then um, let them finish it off. Um, but I also wanted to show other examples of um, interfacing with the outside world. So, one other one that's super useful and turns out to be super easy
13:41sending emails. Um, and then your uh advent of code preview lesson I saw used something a bit broadcasting like. It was kind of doing chunks of stuff at a time with NumPy. And so I was about to teach people how to use NumPy broadcasting. And I thought like, yeah, why do something why teach with something I already know how to do when I could learn something new. So I
14:08decided to learn Tiny Grad. Um, and so I'll be teaching a bit about Tiny Grad and um, how to do broadcasting. We'll eventually also get there.
14:21Excellent. All right. Well, I'm excited to dive in. Where do you want to start?
14:24Okay. Um, so let's start with um, firing up a a server. And what I might actually do is I might scroll down a little bit in my dialogue um to explain why HNA first. So um HNA, if you haven't heard of it, is a German
14:52cloud compute company with a variety of different products. They've got something called HTNA cloud which is a you know got kind of um redundant networkbased storage on shared servers.
15:06Um and then they've got dedicated servers. Um so the kind of the the cloud bits a bit like what GCP would give you and I've already shown you GCP. So you might be wondering well given we're seeing uh Google compute what is it?
15:20Google compute platform. GCP Google Cloud Platform. Why show us something else? So, I actually did a little um got a solver to help me do a little comparison. So, I dumped in a picture of Hner's cloud pricing.
15:39Um so, it's about 5, which is what is that like six bucks um for this computer or like 10 bucks for this computer. Um so then I asked uh and so that includes one terabyte for five bucks or two terabytes of data for traffic for 10 bucks. Um so then I asked uh solver to go away and figure out what the same would cost for Google Cloud and the answer was over a hundred bucks for a
16:10Uh, I was like, "Oh, okay. That's this is where the meat providers get scary is that there's these extra costs." And so I actually went to the Google Compute Engine pricing calculator. They literally don't even mention the network cost, which is terrifying. So, you wouldn't know. But even without the network cost, I tried to find something a bit similar, and that was 80 bucks.
16:38Um, so I sent that off to solve it and said, "Oh, compare it to this." So it's kind of made a nice little table. About the same number of CPUs, the same RAM, GCP doesn't include storage. GCP doesn't include traffic. 80 bucks versus 10 bucks. Um, add traffic, you know, another $100 or $200 depending if you've got quite a lot of traffic. Um, so, you know, 30 times more expensive.
17:05And then I uh went to another company uh this one is I think France-based but they do have um unlike HTNA so HNA has heter cloud has Americanbased data centers they don't have Americanbased dedicated servers OVH has Americanbased dedicated servers um so I pasted in just a screenshot from them and said like okay let's compare that
17:31and uh okay GCP for CPU U versus shared versus 8/16 dedicated 4 gig RAM versus 32 gig RAM, no storage versus two ter etc. 80 bucks versus 50 bucks. Um I was like okay and then if you do want to go in the EU Hner actually has reused servers. So uh end up with a nice comparison here.
17:58You can pay €30 for a 4 core 32 gig on Hznner or 53 for an 8 core 32 gig OVH, 10 bucks for a shared small one or in GCP 80 bucks plus networking plus storage. Um, so, uh, I didn't even mention this, but yeah, solve it. Well, Opus really decided to make a comment,
18:26um, on this, but that's fair enough. Um, so yeah, moving outside, you know, the the standard zone of of big company marketing, you can get much much better um, options. So, we're going to use HTNA. HTNE is also easier to get started with. It's easier to use with the API. Um, it's really fantastic. Um, they have a Pi Pi package you can just install.
18:53Google Cloud doesn't anymore. When you you have to install Google Clouds with a shell, it installs a whole separate copy of Python. It's horrible. Um, it's hundreds and hundreds of megs. So, I I grabbed a API key from HNER. I popped it in my secrets and then um I just pasted in the HNA docs when I first did this, but that was a while ago and it got me set up. So you create a client. So that's the that's the API
19:23client for HTNA and if you want you can add labels. Um so I added a couple of labels.
19:33and then um on HNAE you can add SSH keys. So, I've actually been using them for many years. So, I I already had an SSH key. So, I grabbed my SSH key. Um, and um what we're going to do is we're going to create a computer um that uh is going to have this SSH key pre-installed so I can connect to it. Um and to do that, we're going to use a a standard called cloud init. And so, like
20:02many companies, HNER supports cloudinit.
20:07It's just a text file or a text string. So, this is all the stuff to say here's how to set up my computer before I even connect to it. So, you can say, so I've popped in here my host name.
20:21Um, so you can just pick anything you like. Um, so it's going to set it up with that host name. Uh, it's going to in the authorized keys, it'll put in my public key. [snorts] It's going to set up passwordless pseudo. um uh because I'm the only one connecting to it and because that way then my um tools and stuff can easily use pseudo. Um I like using something called app fast which makes installing software way faster. So I go ahead and tell it to add that repo.
20:49Um and then you can basically just say all right just run a run a bunch of commands once it gets set up. So, I can set it up with my preferred editor and terminal. And then I can uh uh appast upgrade to the latest version of everything and appastall all the stuff that I want. And then set up my firewall to only allow um SSH, HTTP, and HTTPS.
21:19Um, some settings I find quite useful in my SSH config. Um, make sure I've got my SSH config, you know, in the right directory with the right, um, permissions and that's it. So, this is something which you can very easily just ask solver, hey, can you, you know, add this or change this? But most of it, it'll just be a case of saying, oh, I want a different package.
21:44So, you'd like add an extra package, you know. So, so Jeremy, like how did you how did you start this or is this you would recommend like starting from yours if if I didn't really know how to set up my computer?
21:56So, my recommendation is to um upload this dialogue, you know, and make sure you can run it, right? And then it's actually basically good, right? So, like you might not you probably won't need to change anything, you know, and if you do, um just ask for help. So I've had um as an experiment uh I think six um Linux servers running on six
22:25different providers for five years using basically this setup um to see if any of them like get hacked or anything happens. They are all I've not done any manual maintenance on any of them. Once a year I log in and they're all still working correctly. No strange fees. Um, so that gives you a sense of like it's not hard to administer a Linux box once it's up and
22:54running. Um, so it does have to be in a particular format. Um, so cloud init is actually created by Canonicle, the YUbuntu folks. And so they provide something called a schema for this. So, I've got a little function here which um just uh checks uh uh whether the schema matches the file. So, if I go in, so I'm just going to just run above here.
23:23Okay. So if I go into the file and I have a spelling mistake and I say preserve the host name instead then I'll say create my cloud in it and it'll say oh validation error preserve host name unexpected. So um okay run it again. Cool. No problem.
23:46Okay, so we've now got a text file, not a text file, a text string, um, uh, which is my cloud init script. Uh, then I say which data center do I want to put this into? So, I'm going to put it into the, uh, it's called Ashburn because it's in the US. It's Virginia, right? VA Vancouver. No. No. Yeah. Um, oh, no, you're not American either, so I'm asking. I'm not American.
24:12Virginia sounds right. [laughter] Um okay. So, so now we can just go ahead and say all right servers.create uh with this SSH key in this location with that host name. The server type I'm going to use is the 5 one which is about five bucks 50 I think. Uh I'm going to use the latest version of YUbuntu. User data that contains your cloud init script and labels is just tags if you want them. So
24:41you don't really need that. Yes, it is Virginia. Okay. Okay. So, that ran instantly. That doesn't mean it instantly created it. So, if I now uh say server data model, that gives you back all of the data. And it actually says status equals initializing. So, takes a while for it to get that computer going.
25:04And and Jeremy, when we were first writing this um the way you figured out these pieces of API was some combination of the docs and inspecting like inspecting the SVR, you know, what is the server object? Oh, it's something that has a data model. What does that look like? Oh, it's a big, you know, list of keys and values that I can go into. Um, so it's all the solve it way.
25:26We're not we're not rebuilding it from scratch here.
25:29But it's all built the same way that you've seen. So there's a couple of pieces for people to learn about or to give the um uh solvent access to you know one is um api.hetsner.cloud cloud and so we are doing stuff with servers and we are creating a server and so I just passed it all this info um when I first got going and I also
25:58passed it this read me and or you can just read it because this is what we did client equals client service create you know so yeah that's what I had in the context and uh I you know read all of this as well. I find it quite helpful for to understand things properly. Yeah. So um it does straight away give you the IP which is nice. So we can now grab from
26:27the servers data model the public network IP4 IP. Um that's what print it.
26:38Um and so then I kind of have this thing that says while status is not equal to running reload and at now that it's done [snorts] um it's u it's up and running. Okay. So then um I just print out the steps necessary to connect to it. Um it often reuses the same IP when you recreate new servers. So I also tell it to that I
27:07have new keys. Um and I also run that locally. Uh so now I can take this. So if I hit full stop to copy the output. Um and I pop open my terminal. and paste it here. I'm in. All right, we have a server. And um it it says it's up as soon as you can SSH to it. It doesn't mean that it's finished running the cloud init script.
27:57So I also have a little function here called check cloud init that SSH into it and calls cloud init status. Um and then it so if I run that okay it's also finished that because sorry I spoke for too long but [laughter] normally I would have to say
28:32Jeremy, we've uh we've lost you, I believe. Um I'll give Jeremy a second to reconnect. In the meantime, there's a fantastic um comment in the chat that says um if you put all your config files and repos and everything on solve it um that gives you like a it's like literate programming but for infra um which is a grand goal. Oh, Jeremy's back. Hey Jeremy, we lost you.
29:00Zoom just restarted. I haven't seen that happen before.
29:03Okay. It was obviously too heretical the the knowledge you were imposing. Um the last thing I said before I got disconnected.
29:11Uh you would you you usually have to check for the um cloud to have finished but because we'd been speaking for a while um you didn't need to use that um that little weight.
29:22Um but yeah, so I was just going to say I mean I guess it's a good question for you. I could also create a server by going to Hner and and clicking the buttons in the um in the dashboard. Um yeah. So maybe what's the what's the difference and what's the motivation for if I'm probably only going to need one still doing it this route.
29:44Um I would do it this way because you'll have one set up just right. Um I do actually have something called um fast server um no fast setup which has a shell script.
30:05So you could run this shell script and get the same kind of thing. Um yeah, I think this is easier um even to do it once. It's like literally upload, hit shift A, you know. Um yeah, and you're done. Um and then it's quite likely you will want a second one at some point. So, you know, or you need to shut it down or you mess it up.
30:32Yeah. Yeah. Exactly.
30:34Um, and then you know now that we're up and running, we can use the exact things that John O was using last time, right?
30:42So that's where that function came from. So this is now running on my IP. So um, so I keep my email in a secret and my name is not secret. So I can go ahead and run get config. Um, and so having done that, you'll find there is now a get config file on my remote computer.
31:07So this is this is how you can now have um solve it, help you make whatever you want. And so we've got UV on it. Um, firewalled UFW status is running. Um, so it should be pretty good to go.
31:28Uh so then I you know it's not a bad idea just to check with um the machine to check does it look all right and you can kind of ask questions about security and stuff like that. Um so here's the homework for folks. um uh create a server
31:56um and then uh install something interesting into it. My suggestion for something interesting that you might find super helpful is Wire Guard. So WireGuard is a really nice VPN.
32:10Um, and it's one of these things which there's a commercial version of it called tail scale and you can spend money to purchase a tail scale VPN. But actually the starter per user costs more than a single heter server. And now that solver can help you, you can set up a VPN at the same time as
32:40learning a lot, you know, and um yeah, uh you've got pseudo access, etc. Um so that's my suggestion is is learn about why wire guard's cool, what it might be useful for. Um, it's not only for watching British snooker tournaments that aren't um available in Australia, but apparently you can use it for that. Uh, [laughter] yeah.
33:09Once you once you have a an always on server in the cloud for five bucks a month, you'll find that at least I found it's it just becomes like, oh, well, let me see if I put that on there as well.
33:20Right? you end up putting up a personal website that's a little quirky and then configuring something that just hosts some cool HTML files that you wanted to share and then also learning a little bit about Cloudflare if you want to redirect a different URL to it. You know, it's just a nice little um tinkering space and um like Jimmy said, the nice thing is you can always recreate it now that you have your master. There's a lot of there's a lot of things you would otherwise be paying for like
33:50scheduled tasks. You know, a lot of people will pay for some service to run schedule tasks, but once you've got your $5 an hour, sorry, $5 a month machine, you can run Chronab and stick in any Unix command you like and it's up and running. Uh, somebody in the chat reminding me, yes, Tails scale is free for personal use. So, um, create a wire guard VPN anyway.
34:14[laughter] Um I I like I like that also this the control of having my own VPN on my own. Like nobody's ever going to like have locked out that IP address because somebody has done something naughty with it, you know.
34:35Um, okay. So, the next one I was going to show, um, oh, somebody's saying they've seen people get blocked on tail scale. Yeah, I can imagine. So, like tail scale is a free service. It's it's they are going to have to be careful about what people use it for. So, um, if you've [clears throat] got your own machine, it's everything's a bit easier.
35:02Um, so yeah, the other one I wanted to show then is um sending email. And this one I tend to have the same message at the top of every one of my dialogues. If you're wondering why, there's much more stuff than I use. [laughter] Um, normally I just have this, but you know, it's nice to have dialogue helper. It's nice to be able to display IPython stuff, etc.
35:28Um so I had um solve it take me through how to send emails from solv. So why might you want to send emails from solver? Well again it's connecting you to the outside world. So uh you could also use the same thing to for it to teach you how to read email. So uh Gmail supports something called IMAP um which lets you read email and search email.
35:51Um, so you can use solver to automate everything in your, you know, and every provider provides SMTP and IMAP and stuff like that. So it's not just Gmail.
36:02Um, so, uh, I use this, for example, to send emails to all of you lot. Um, uh, we have a solvent dialogue. We have, um, 30 30 something thousand addresses from our forum of people who want to be kept up to date with stuff. And so solve it uses this. Um, we don't use Gmail's SMTP for that. You should only use Gmail's SMTP for sending
36:32smallish amounts of personal emails. Um, for um larger email sending, we use um something called um SCES um which is the uh SMT, Amazon's SMTP, which is very good. Um, and then, uh, there's another really good one I quite like called Elastic Email. Um, which, uh, yeah, you can also
36:58play around with it if you like. Um, anyway, so we're going to use Gmail because this is just for sending stuff from from me. Um, so in learning mode, as usual, I like to start out with who I am and what I'm trying to do. Um, so in Gmail you need a special thing called an app password. You can't use your normal password. So it can teach you how to do it. And so here I used screen sharing.
37:26And I said tell me what to do. And it double checked that I've got two-step verification and how to what to do. And um that all work fine. Okay. So I got my password. Um, right. So, run up to here. Oh, I don't really need to share right now.
37:53Ignore that. Um, and so I said, let's just check it. So, I just have it just had it dump out some code. Um, which I went and ran. So, it creates. So this is all using stuff built into Python. It's got an email message class. You set the content. It's got an SMTP lib class. So you create the server connection. And I didn't have to provide any um context because this is stuff that's it knows from the training
38:25Um and I sent it and I went and checked and it worked. So that's kind of the most basic version.
38:35And again, I think it's at the point level though of like too many moving parts, too many things to get wrong to leave it there. So a few years ago, um I was really shocked to discover there are no Python libraries that make it easy to just say um use some server to send from some address to a bunch of addresses. for each address have a different insert that you put into a template.
39:08Uh add attachments and send them all. Um didn't exist which really shocked me. So I I needed it so I made one. Um so that's what markdown merge is. Um the whole thing is including imports and whatever else is less than 100 lines of code. um of course um and basically it's uh send messages. It creates an SMTP key
39:37connection until it's gone through all the addresses. It creates the message. Um you can even use markdown which is quite cool. Um I've got a test mode otherwise it sends the message. Uh automatically handle sleeping to avoid overloading the server. Uh also most servers have a limit on how many you can send per connection. So every 100 it quits and reconnects. So it's all set up designed to work nicely. So um so you can install it.
40:10Um you can import it, set up your SMTP config, set up your recipients. Um and so here I want to in my body I've got a template. Um, so these are my inserts. So the first person the name is the port and the second one the name is Jeremy and um I've used markdown.
40:39Um so I then go ahead and create my email and send and um so our um virtual legal and professional services group wanted to use this. So I wanted to make something easy for them. So I then said like okay write a helpful description um which I then pasted here.
41:06So um yeah Luke and Alexis if you're watching this is what to do. [laughter] Uh hope that is what you provide what you want and it also you can add um attachments as well.
41:25And Jeremy, there's um you know, there's lots of products for sending automated mail. Um there's lots of products for monitoring a server and sending you an email when something's going wrong. Um it just we at Answeri I don't think we have any of those type of subscriptions, right? if our No, we well we we did because I thought like, oh, I want to send messages to our 30some thousand community members.
41:53[snorts] So, I signed up for the [clears throat] two ones that's currently seem to be most most well regarded, which are um kit.com and can't remember something else.
42:05Yeah. Yeah. And I played around with them and it's like it's funny. The person I asked for that advice was Hamill that a lot of you know. And Hamill was like, "Jeremy, I promise you're going to end up making your own because they'll piss you off." And I was like, "Oh, no. [laughter] I just want to send some emails a week later." I was like, "Okay, Haml, you're right. I made my own." Um, yeah. So, this is better. I find this better than any of the commercial providers.
42:31Um actually if you are sending it to a whole lot of people you do need a um uh an unsubscribe. Um and actually I will show you our um highly proprietary unsubscribe um [laughter] system. Uh let me try and find it. So that'll be in our landing page.
43:02I'll I'll also say um if you're watching this a couple of things to just be a little careful with. One probably if you're doing lots of experiments maybe use a test email address rather than risking your own personal precious Gmail account on something. Um another you're entering in API keys especially for like setting up servers and stuff that are linked to being able to spend money. So don't share your solvent instance for example where those are all environmental variables that someone
43:30else could read. Um yeah just keep a little bit of an eye on and don't spend obviously like and and like you need to you know have working unsubscribe addresses and stuff. This is um our entire email marketing system. I created a single SQLite table called mailing list and I created a stop email route that [snorts]
44:00so if you send a message to solve.it.com/stopemail it.com/stope email question mark email equals it will unsubscribe you and uh if you write start and like it's so funny John you know something I've told you so many people sent me emails say I accidentally unsubscribed I think a lot of people like oh I wonder what happens if I click on this link it's like you're unsubscribed uh so I had to add a start email for other people so anybody's accidentally unsubscribed you can resubscribe
44:29yourself with question mark start email equals email chess. So yeah, that's it. What is that? That's uh less than 20 lines of code. [snorts] Lovely.
44:42Um all right, so Jonno, um Monday is Monday US time is our next class, but midnight Monday, Advent [snorts] of Code opens up. So there will be time before the next class to start on the next Advent of Code. So, uh, we should, um, prepare ourselves, should we not?
45:10So, to give all of you an idea of what to expect, we've been talking about deliberately, slowly, mindfully honing your craft, um, focusing on the rabbit holes that interest you and and everything else. Um, when Advent of Code the live version starts, there's a leaderboard with time to finishing and we'll almost certainly have a leaderboard for just solvent participants. And so the really really tricky exercise.
45:38I think they got rid of the leaderboard this time. I think they might have the private leaderboards, but I think they got rid of the public one because people are taking it too seriously.
45:45Right. Okay. Well, I was going to say, yeah, if you can resist that pull to just attempt to finish it as fast as possible, we'll get the AI to solve it for you.
45:54Um, but it is really fun all doing it together at about the same time and then seeing how everyone else did it, seeing if you can one up each other with, you know, cruel and unusual ways of solving it or extremely efficient ways of doing the part two. Um, it should start.
46:09I've had the same conversation with many people which goes something like this.
46:14Oh, AOC. Yeah, that leak code stuff, I don't like it. And I'll be like, well, did you know that each one is generally carefully designed to teach you something really interesting? For example, last year there was one that taught you how registers and up codes and virtual machines worked and held your hand as you went through and learned each step. Or did you know that there's one which teaches you how to use convolutions?
46:36Like, no. It's like, well, it's not le code, you know, it's it's delightfully made. Well, we haven't seen next this year's but previous years they're delightfully made designed educational tools that are perfect to use and solve it because in that poly step with the reflection like okay tell me about this is there totally different ways I could have used have I have I missed the point of this exercise um yeah
47:05yeah yeah it's really good someone was complaining to me oh you guys said code is like leak code but leak code is completely it's sort of evolved further and further into its own weird little state. Um, but advent of code is nice because there are some things where oh, if you knew this was graph traversal or whatever, you know, you you know the fancy computer science term, it can help. Um, but also, yeah, going through it your own way and figuring it out piece by piece is is definitely a lot quite fun
47:33from the couple of years I've done it.
47:35Um, oh, somebody did point out in the chat sorry about email before we get to you, Jonno. Um you don't have to use AWS or Gmail or anything I think you can run your own SMTP server on your own um instance. Um there is a really great piece of software called open SMTP um which is written in Go if I remember correctly and I've used all the stuff from our forums actually is sent through our own SMTP server. The issue is nowadays um SMTP server deliverability
48:04is tricky. Um, Solvet, I've had Solvent help me through the process of setting up domain keys and DKIM and all the co signing you need. Even after it's all set up correctly, quite a few servers still won't accept your email. So, there's something to be said for using third parties for sending email that already have good reputation. Sorry to interrupt.
48:29And yes, there will be 12 puzzles this year rather than 25. Um, so that's the other change, but it'll be two per day for 12 days. So if you do one a day, then you'll end up getting about to Christmas.
48:43Cool. Okay. Well, um, speaking of Advent of Code, I did have a sort of example meta tip for um, working on that that we could go into or we could take a quick break now and then do that after the break.
48:55Let's have the meta tip and then that'll hit us about on the hour and then have a break. How does that sound? Uh the metatip being part of my whole Oh okay. Well in that case let's have a break. So 5 minutes 5 minutes break sounds sounds
55:31Okay. Give everyone a second or two to rejoin. And um I have a stretch. I should have done that while I was I just went and had a sit. I should have probably had a stretch.
55:46Okay. Um, cool. So, as promised, um, we are actually going to do some Advent of Code today. Um, and I thought I'd take a look at a slightly trickier puzzle from last year. um and use it to illustrate a technique that is often very often incredibly useful for me um that we haven't necessarily covered in some of the earlier advent of code examples and
56:14that's creating visualizations. Um so excited this we'll see how it goes. it's not going to be um the most flashy shiny thing, but especially if you're dealing with any kind of data, like I'm a data scientist by background. Um, and the first thing you do is often create as many different plots and visualizations and ways of seeing as much of the data as possible and that shows up so much. And so in past advent of codes, minor spoiler for
56:44past years, um there have been things where like there's some question about finding the furthest distance some elf pushing a wheeled arbarrow can travel in some number of steps. And if you just treated the input like a black box of text, you might never notice some subtle hidden pattern. Um likewise, I think there was one where So that was a matrix that you plotted where the ones and zeros were or something. Is that what that is?
57:08Right. Yeah. Um, I can pull it up. Um, if I go to I can show you the the plotting or what it orig the input is a bunch of dots and um, pound signs. So that doesn't mean it look like much there. Yeah.
57:32Yeah, exactly. So if you just printed this out, you'd say, "Okay, cool. Somewhat random scattering." It's only when you um plot that as a grid that you see the the pattern emerge. And there's been a few of these over the years.
57:41There was one where, you know, there's I remember this one dots moving around and occasionally they' sort of align and even more occasionally they they'd form a special little hidden Easter egg. And um it's funny there's possibly like programmatic ways to find that in in advance without knowing what it looks like. But Jeremy and I both independently had exactly the same solution, which is make it Oh, did you?
58:04Oh, yeah. I tried. I mean, I got it this way, but then I tried very hard to do it the automatic way because like I was thinking like it said some the problem said something like, "Oh, find the picture which looks suitable or something, you know, or find the matrix that looks suitable." Like, it was really vague.
58:21And I thought, "Oh, it's probably going to be a picture, so it's probably going to it probably be a Christmas tree, so it'll probably have blank corners." So I looked through to find all the ones that had blank corners, but like yeah, it's like snow or something and it broken. And I was like, "Okay, it probably be in the middle." So look for anything that's symmetric. No, nothing was symmetric.
58:41So I failed at the automatic approach.
58:43Well, I turned it into a video and then I just scrubbed through until I saw something.
58:47That's what I did eventually. Yeah.
58:49Um Yeah. So that's going to be the I guess the extra arrow in your quiver um that we're going to practice today on this problem. Um, and you'll see how it ties into the problem solving technique as a whole as well. Um, but yeah, my baseline advice whenever you're facing something, as soon as you get any sort of difficulty above the like day one advent of code, figure out if there's a way you can visualize it and that'll often produce some sort of insight. Um, okay.
59:16So, that's that's setting the scene. Um, let's take a look at the problem that we're going to tackle today. Um, I might only do the first part and give that as homework or um, leave it dangling. Uh, day 15, warehouse woes. So, you're in a mini submarine. Um, there's a school of lantern fish swimming past you and they're pretty anxious. Um, they need lots of food and they have an incredibly elaborate warehouse complex operated by robots for keeping them supplied
59:47Um, but there's a robot on the loose.
59:49Um, it's running a mock pushing around boxes. no regard to logistics or inventory management and they're not brave enough to go try and turn it off because who knows what it's going to do next. Um, but if you could guess what it's going to do, they could maybe find a safe option. Um, so they have a list of moves it's going to try and do, right? That's our puzzle input. And they have a map of the warehouse. Um, but sometimes there's a wall in the way, so it's a little tricky trying to predict where the robot's going to be. So I
1:00:18guess the at is the robot and the circles are boxes.
1:00:22Exactly. At is the robot, the circles are boxes and then these are walls and the robot can't and dots are empty space both.
1:00:29Exactly. Um and so yeah, this robot is going to try and move. And they've given us a description of what it's doing. If there's boxes in the way, it'll attempt to push those boxes. But if that would cause it to push a box into the wall or if the robot itself is going to hit a wall, nothing moves at all. Right? the robot stays where it is. Um, and so we have to figure out what's going to happen. And you could imagine starting right away by
1:00:57digging in and writing um your like calculate robot moves function. Um, but the problem is it's not like one of these previous examples where there's always been split the lines, take the first thing, subtract the second thing, add those up, you know, one line at a time kind of deal. Here we're kind of having to think through, okay, it's trying to move.
1:01:18Which direction is this moving? It's moving in some direction. Is there a box? And if so, is there another box behind that? And what if there's a third box behind that? Is there a wall after that? What should happen? Um, and as soon as you start to see something feeling a little bit like, oo, am I am I just going to write 20 lines of code all at once? Um, or maybe 200 lines of code all at once for some really complicated thing, it's a nice chance to say, okay, is there a way we can set up some when it doesn't work the first time, you know?
1:01:44Mhm. Um, particularly if it works on the sample data but not on the full data. All you get back is a Jonno, it didn't work.
1:01:51And it's that's just like makes you want to go crazy if you don't like have any system for figuring out what the hell just happened.
1:02:03And a lot of stuff in the world is like this, you know. [laughter] Yeah. Um so very kindly the um the puzzle description includes some extra pieces for us. They have a simpler state to practice on. Um and then they also have a list of moves. And so this is a really good way of seeing like building our own intuition, but a little bit ugly in the in the um text version, but whatever. You can see if we start from here and we try and move left, there's a wall in the way and
1:02:33so nothing's going to happen. Then if we move up, we move from that little position where we were up. So you can see this little at sign is the robot.
1:02:41Um, and so the first thing I like about these AOC puzzles, Jonno, is they're good examples of little domain specific languages they create just for the purpose of a puzzle. You know, I really like the way they're showing showing this and you can do it all with just text.
1:02:58Exactly. Um, so what I've done is pasted that example in here. Um, and I thought a good first step would be maybe we can use this as a test to say like can I set up some way of measuring is my function implementing all the rules correctly.
1:03:16Um, because we very conveniently have these pieces of here's a state and then the move and then the next state that it should be. Um, so maybe Jeremy if that's okay as a good starting point we might try some test-driven development first write some tests then write some visualization and then um proceed from there. Um, let me see. I guess so. That sounds reasonable. Yeah.
1:03:36Um, it's quite a good way to do these kinds of AOC type things. Um, Mhm.
1:03:42Yeah. because otherwise you can kind of convince yourself that it seems to be working, but if you didn't have some little tests and it can be a bit harder.
1:03:58So, this is my um my first little piece of work that I'm going to do. Rather than trying to tackle the grand problem, I'm just going to deal with this example. Um and so um yeah, let's get to it, I guess. Um the first thing we might want is the moves. So, I'm thinking I'm going to look through the example for any lines that start with move. Um so, I can go here.
1:04:23Um, I guess I could go lines is equal to example and then just check out 10 or so to get a feel for them. Maybe 12 so that I can see the piece that I want.
1:04:41Um, okay. So then I could go um L for L in lines if L.AR starts with move something like that.
1:04:53Spelling mistaken starts with thank you. So there we go. Um fantastic. Um okay and then at this point might just show off a little magic trick. Um [laughter] because um I want to focus on the the fun bits.
1:05:12Um can you show us your little magic trick actually cuz it's I know it's a secret magic trick but it's actually so cool.
1:05:18Um, yes, it doesn't have to be it doesn't have to be secret at all. Um, so for um for this demo, I I realized I'm feeling a little bit foggy today. There some bits and bobs that I might want to copy and paste from my previous solution. So rather than manually going and copying and pasting and looking like I'm just cheating. Um, instead I have a little fast HTML application running and I've loaded up my I secretly prepared this in advance solution. Um, and then I
1:05:46have two routes. I have an append route that takes one of those um previously written cells and puts the source in my current dialogue using our um dialogue helpers add message function. And then I have a page that just shows a styled version of every message in the dialogue. Um so if I go over to my separate browser, you can see here I have these um this is my uh my original version of this dialogue. So if I click add, it's going to go and add that cell
1:06:16to the the current dialogue that I'm showing. Um, and I also have that on my phone. So if I see that, okay, the next thing we need So you're using your phone as a remote controlled solve it.
1:06:28Yeah, just like a I feel like only Jonno would feeling a little bit less than 100% would be like, okay, therefore I'll just write a whole new web application for controlling solit. But I think that's great.
1:06:42Yeah, [snorts] you can see, you know, it's not it's not that much code, right?
1:06:44It's just a fun little um application of I love that you're doing it on your phone. That's so cool. I think it's the first time I've heard of somebody actually using Solvent on their phone successfully.
1:06:53Oh, so I'm not looking at Solit. I'm just looking at the app my special web page. Yeah, my special app.
1:06:59Um, okay. So, I'm happy to re rewrite this code. In fact, um, I I didn't like it the way I did it the first time. So I might actually write most of this manually, but if you ever see magical pieces of code popping into existence, now you know my um my secret, right? So I can mainly I was thinking, oh, it'll be really fun for like adding all the notes and things that um had in the dialogue, you know, if we've done something and I want to add a new heading, you guys don't need to see me type.
1:07:25Um okay, so and somebody on the chat says, why why copy and paste when you can just create a whole new web application?
1:07:32Yeah, it's um it's already probably overtaken in time. Um, oh, okay. So, now we want the states. So, I could go um sample.split. Um, and this has got two new lines um every um piece.
1:07:52Exercise for the reader would be rewrite Jonno's moves thing by doing re.find all. Um you could get them all in one go that way.
1:08:01That would be nice. That would be nice.
1:08:03Um, and if you're uh depending on what you're trying to get out of the advent of code challenge, I think it's really worth practicing all the little bits. But um you could also always um oops for something like this where the main challenge for me is how do I move the robots? What are some fun things I can do? Um if you had to say um let's grab the states
1:08:29numpy arrays. there's um there's no one but yourself accountable right to say you know are you getting what you want out of the challenge you could just say solve the problem and Sonet would do it um and you are in concise mode here so it's going to make no attempt to not just do it for you um some folks um on Discord have had some success by um pasting a summary of Polia's steps at the top of
1:08:59their dialogues um which they found extreme helpful. You could also paste at the top a summary of like what you want to get out of this process. And so just ask it to remind you if it sees you, you know, not following that process.
1:09:18Yeah. And um you can always put it in learning mode and I've modified its response so that next time I ask it for a cheaty bit, it's probably going to tell me, wouldn't you like to do the step by step? Um, okay. So, we've pulled out our examples here. Um, and we have, um, 15 moves and 16 states. And so, um, this just gives us a way to quickly generate some test machinery that says when I start in state one and then I apply the move, do I get to the next
1:09:48state? Um, and so the way I'm going to do this is um, import test EQ from fast core. You could also just use an assert, but test equal is nice in that it shows you the failing cases. Um, and so then we can can you just type uh test eq question mark question mark and then could you also import test? So we can do test question mark question mark.
1:10:21Um, that's all it takes. That's That's so like Fast Core has invented a complete testing framework. [laughter] Um here it is.
1:10:31It's like I couldn't find anything else that just did this. So [snorts] when people are like, "Oh, not invented here syndrome, you know, why are you doing everything yourself?" It's like, well, it's not too bad actually.
1:10:48Um yeah. Okay. So to write our actual test, I've thought of the key function that I want is given the current map of the warehouse and a move direction, what is the new map of the warehouse look like? Where's the robot? Where's everything else? And so I've written a little dummy function that just assumes no move is happening.
1:11:07And so it's your goal to end up with like where does the robot finish or where do the boxes finish or like what's the final thing you need to know? The final final thing, they have some GPS position that is the location of all of the boxes represented as a number and added together or something like that.
1:11:22Got it? But if you can represent the final state of the warehouse, then you can compute that final single number that you submit pretty easily.
1:11:30Um but actually figuring out how the moves will go, that's the like core piece of the logic here. Um, so four I want the um starting state, the end ending state and the move in our we've got a list of moves. We've got a list of states. So I can use zip to say um all but the last one
1:11:58state states the second one in the list will end. So this is like um beginning, end, and then the move that went from the beginning to the end um moves.
1:12:15Um so this is quite a nifty trick you've got here. It's a very common algorithmic trick. So zip creates tpples of the first thing in the first list and the first thing in the second list and the first thing in the third list and so forth. Um, and what John has done there of saying states colus one, states one colon is a super smart trick which basically means you're going to have the first two items and then the second two items and then
1:12:44the third two items and so forth. So it's a a useful idiom to know. Yeah, just to um show it here. Um, if we wanted 1, two, and three, and then a separate list two, three, and four. And then if I zipped them, them together, it's going to give me You need a zip. You need a list on that.
1:13:07Or you could do l.zip list. Um, there we go. It's going to give me one and two, then turn three, then three and four. Um, just making life a little bit uh more convenient.
1:13:19Um, but all I want is to be able to get move zero, oh, sorry, state zero, state one, and the move that went from that, and then state one, state two, and the move there. Um, so we want to test that if we say move from start with move. Uh, and actually, I shouldn't call this move. I should just [clears throat] otherwise I'm going to overwrite my function. Um, this should always equal end, right?
1:13:47Um, and so if I now run the test, it's going to fail because on the very first example, the input state and the output state um are not the same. Sorry, the input state passed through a move function should look like the output state, but it doesn't because we just returned exactly the same state that we put in.
1:14:07Um, but what it means is we've got a machinery hopefully um to test our function. Now, annoyingly, how do you test your test? Um, if it was any more complicated than this, you might be a little bit worried. Um, luckily we do also have a super smart AI that we can say, can you tell me if my test is right? Um, just to give us a little bit of an extra sanity check. But you'll see in practice, the main test is going to be our visualization. It's just nice to have since we have this beautiful set of
1:14:36test cases, we might also do some test-driven development and make sure that um, yep, test looks good. Fantastic. I've noticed you're [clears throat] not using thinking mode there. Um, and it's totally fine because these are pretty straightforward things. I just wanted to mention like during the week um so at for this year, for the rest of the year, we've got Opus, the latest version of Opus uh for free in thinking mode.
1:15:03Um, and I've been using it a lot and uh I've definitely noticed it's got a bit more taste, you know, and a bit more thoughtfulness. There was a really great one I did yesterday where I had forgotten to run one of my messages and then I ran a different message and got the wrong answer and it was to and I said like oh can you know and it was to some code that that it had written. So
1:15:33it's like oh it looks like you've got a bug and normally it'd be like oh you're totally right and it would hallucinate some stupid bug. Um and it said like let me check the logic. Uh actually all the logic looks correct you know are you sure you ran all the messages and I was yeah really impressed um h yeah that
1:15:55um okay and it still follows learning mode that's good to see um okay so um we have a way to test the moves um what else actually this is a good prompt for solvent it um what else will be useful for us because at the moment we're still just like laying the groundwork, building up some utilities. I'm thinking probably getting the location of the robot is a useful function to just do on
1:16:23its own. Um, yeah, visualization will be nice. Direction mapping. Um, okay. All three of those sound fantastic. Um, so let's do let's do visualization. And so for things like this, um, when I tried this yesterday, I was thinking, okay, how would I visualize this?
1:16:43Mattplot lib, right? To show the grid as an image, set some different colors for the different values. Um, I never like writing mapplot lib. So, I went to solve it. I actually, I think, used concise mode. I said, um, create a visualization function. Um, and what I got back was one of these like little delightful moments. Um, oh, and it's done it again.
1:17:06Fantastic. I I wonder if this is data contamination. Um, and someone else wrote this beautiful visualization function enough times that it was put out on the internet. Um, but isn't this cute? [laughter] It's so much easier to see where the little robot is and where the walls are and where the boxes are. Um, it's used a dictionary which is very nice simple way to Yeah. go and convert each map each one.
1:17:33Yeah. Um, okay. So now we have a little visualization.
1:17:37Um, and so then just to explain there, you've got a join in a join. So it's it's you can work through this in a number of ways, but one would be to work outwards in. So if you go to the far right, it's going for each row. Um, and then for each row, it's doing the thing in the middle, which is to go through each C in row.
1:17:56And so for each C in row, it's going to get the correct color, join that up together to get your result for each row. And then finally on the far left, join that up all together with a new line.
1:18:07is building it one line at a time looking through our um state which is uh just that. So the first one is going through this line. They're all looking up in colors. They're all the black um character and then we're joining all those together with no spaces. Um yeah, it's a very very Can I just show you one trick you could do if you didn't have the visualization?
1:18:30The the really fast way to do these kind of thing is I think um what I often will do is just be like um for S in states print um and that should go through each row you know for S in states I would say rather than state zero.
1:18:52Oh uh yeah okay that's interesting. What are those? Are those what are they lists or numpy arrays or what? Yeah, they're numpy arrays. Um, and it's for each of these um each of these blocks. So, we split it on the double new line.
1:19:06Yeah. So, just say print double uh you know empty quote jojoin s and you know so that's a slightly shorter version. Um yeah, which should work and it's and much less nice but it's not terrible. It's better than the big ugly one.
1:19:22Better than the big ugly one. And if I remember like there's often a lot of grid like challenges in advent of code and we we both ended up with variations of show grid in our utils.py when we were working through the challenges last year.
1:19:38It's a good test for kind of that little you know SDK API skills you know is to try and make it so that you know each time you see the same thing in AOC two or three times try to factor it out. click on that little export button. Um, and then you can use it in your next AOC challenge if it comes up again.
1:20:07Um, I could have sworn there was a useful function that would help us here. Um, oh yeah, I think it's ND do npware, not state zero. There's a there's a very weird thing in numpy where a lot of its things that ought to be array methods are not and it annoys me.
1:20:29Okay, so we want the location where the grid is a robot. Um and yeah, you could also write um copy that message and um on the copy of it remove the np.ware. So it just states zero equals because this is going to be relevant to what I'm talking about later.
1:20:53So what Jonno's done there is he's compared a matrix to a scalar to a single character. And so it's this is the first example is in a broadcasting. So what it's done is it's basically acted as if the right hand side was a matrix containing the letter at lots of times which is very handy thing that numpy does and pietorch does.
1:21:25Yeah extremely useful. Um okay so if I get lock on state z. Okay. So, you've this is the classic thing we've talked about where you've done it manually once, you've made sure it worked, then you've wrapped it into a function, then then you've called a function, then make sure it still works.
1:21:42Um, cool. Okay. So, I think um we're feeling almost ready to start working on the um on the movement, I guess. Um yeah. Well, let's let's build a visualization now that lets us test our move function. Um, yeah, and feel free to like, you know, paste in the actual [snorts] moving bit when you get there. It's probably not the main purpose of this discussion.
1:22:09Okay. Um, so let's see. Um, I guess we need to know what the the the directions are.
1:22:19Um, and I'm hoping that um the uh ghost text. There we go. smart enough to know what I what I want here is so that was command shift full stop I assume yeah command shift full stop full stop um so that I can say okay if it gives me the um symbol to go left what does that mean in terms of moving in um rows and columns and so um if I want to go to the
1:22:47left it's saying that my first index which is the row will not change and my second which is the column will go down by one um classic AOC pattern this using to represent coordinates. So at this stage um I So anybody who's like JTO just jumped to a point here where it's like this is pretty nifty and so if you're watching the video or whatever and you don't get it like stop explore or maybe in a couple of minutes once he shows you how
1:23:15to use it because this is a a very cool technique uh just like that zip one I showed you talked about earlier. Yeah. Um, okay. So now I already have a fast HTML app from my um little magic earlier. So I can just decorate something with a um a root, which is pretty convenient.
1:23:38Um, we have this show grid function already. Um, but what I'm actually going to do here is make a little game with the um, well, how do we want to do this? You need a type annotation on your s.
1:23:57Yeah. So I'm thinking maybe if I just pass the index or I actually want the um the state as a string, right? So if I did this um we currently have them as numpy arrays. [snorts] So I'm just wondering if it's worth um yeah it' be very easy to join them and have carriage returns at the end of each line. Then that would be a string.
1:24:21Okay. Um, so should we uh should we write that first?
1:24:29Um, okay. So, we're just trying to think what do we need to to render this all out. Okay, so def um state do store.
1:24:38And the nice thing about that is your any existing code you have will almost exactly work. You just have to call dotsplit lines first because you can loop through a string. Oh my gosh. Um states um okay instead that'll be a bit easier if you Well, we want to use it um to send things. Oh, but you're saying No, I don't just for your example. Yeah.
1:25:12Right. Right. Right. There we go. Right.
1:25:14Um, so take our numpy array and and I guess this is actually like an equivalent to your visualize function that's a little simpler. Um, okay. So given a state, we can split lines and that will give you something ready to use, I think.
1:25:31Mhm. Um, so we call it show grid. put an extra parenthesis there like that.
1:25:43Um, and then what I want is a route that um given a state and a move applies the move and returns the new state.
1:25:56Um, so defly move, it's going to take a state and it's going to take a direction. Um, and so this is going to say, um, new to move.
1:26:21And then call it a state in the top and s in your call. Maybe call it s in the in the par.
1:26:28Yeah, let's call S there. Um, okay.
1:26:31Okay. And then I want a window or some sort of UI so that I can see buttons to do you need to do a state to stir on the show grid as well so you can return a string instead of a numpy array.
1:26:46Um or you're going to turn it into a fast HTML thing later.
1:26:52Yeah. So we're going to we're going to ultimately end up wrapping these in um in fast HTML. But actually I could I could say um read um state you're right. Um
1:27:09so I've just this preview here is eventually going to be how we render it in the in the user interface. Um so I can reuse that as a function. Um our move still does nothing, but that's okay. And so then we need buttons for clicking up and down. Um, so I could just go make a route for the controls. Um, and I guess this needs an initial state. Um, and this is going to have heading game.
1:27:54Um, it's going to have the preview.
1:28:00You want to close parenthesis after your H1.
1:28:06It's going to have some buttons. Um, let's just show this um and build up. Um, trying to do a lot at once, so it should slow down. Okay, this should be a string if we want it and well actually it doesn't matter.
1:28:34Yeah, it does. It needs a annotation to be used as a route. So if you you need it at some point um and so if we don't get any like if I just load up the page we can just use the original state um but as a string and then
1:29:01now hopefully I also need to pass in Okay. Um, we're making some progress. We have the game, but it's not displaying right.
1:29:16This actually is correct. I think it's just that um HTML doesn't render your lines. If you had a pre around it, it would have Yeah. So, let's do this. Might actually be all we need.
1:29:32There we go. Okay. Um, so at the moment we don't have buttons. We want buttons where when you click them, they take the current state, they apply the move depending on which button you clicked and then they um show the new state. And so that's surprise in the chat that that you're creating a web app. Um, and I think maybe that's because some people yeah feel like creating a web app is some giant thing you do when you have a major
1:30:00enterprise customer in 3 months time.
1:30:02But like no, I mean um particularly with fast HTML and solve it making a web app is something you absolutely can throw together to solve a quick advent of code thing or like Jonno did literally this morning throw together a um remote solver driver um to help add messages. Um it's definitely something you can do in just a couple of minutes and feel free to use your remote solver driver as much as you like. Jono, you're
1:30:31not at 100%, so don't feel like you have to Oh, look. It's doing a lot of nice gross text as my remote driver apparently.
1:30:40Um Um Okay, we got some starting issues, but yeah, if you import uh if you're from Monster UI. Star, then they will look correct.
1:30:54I think I've done that. It might be that they need to be in a um You sure you have?
1:31:05Uh right click on them and check. But just so that my buttons are proper buttons.
1:31:17It's taking a while.
1:31:18It's a slow import.
1:31:21Maybe it's N. There we go.
1:31:23Okay. Yeah, there we go. Um, cool. Okay. Um, it still does nothing because our move function still does nothing. But I think now we're ready to define a move piece. Um, so I'll get the location and then I'll get the um, well, let's see. So, we're taking in
1:31:55a list of lists or an Empire array. Um, so I'm going to say the current location I'm going to set to empty. And the destination location I'm going to set to being a robot. Um, how do I know the destination location? Um, I'll call it DR and DC. They're going to be um
1:32:22the direction that we look up for whatever this string. So, this will be like the little up sign. This will give me the change in row and change in column. And then my um new row, new column is going to be my yep, my original location plus dr. My original location plus DC. Um, and so we are going to, this is trying to solve it for me, but I'm just going to say, um,
1:32:49state new R new C is equal to robot and state I guess I should say um, RC is equal to, um, like that. Then I can just say so notation here is helping me. I'm trying to think through like what are the different pieces.
1:33:15Um this still is a fair chunk but um line six can change to R and C.
1:33:22Yep. So um I mean keep doing this as you are but I was just going to say I I suspect I would have done it by turning the get the location into an array and then I can just add the tpples together.
1:33:37[snorts] Oh, okay. So, it is an array. Um, and directions directions is the one that you'd have to turn into an array.
1:33:56Um, so you could say, um, so I could say, um, new new lock is equal to lock plus.
1:34:25So, we're just trying out this idea to see if we like it. Um, two two and then we went in this direction and we have the new location. Okay. Yeah, I like that.
1:34:34So, again, this is like kind of broadcasting, but this is the simplest version. So, Jonno here has two um they're actually matrices because they're are kind of that's why they're two square brackets, but you can think of them as vectors. They both got the same number of elements in. So, numpy will do um elementwise operations, which means it will go through and it'll add together the first ones and then it will add together the second ones
1:35:08and then we can say I'll state at the um you can just use indexes like this, right?
1:35:16uh kind of depends on the details but should be possible. Um just depends a bit on what all the different types are.
1:35:28Um we have a show show grid states zero.
1:35:39Uh, right. I should print. Actually, what do we call our function preview, right?
1:35:46Um, I could say, uh, well, I guess it's still going to show fast HTML. I I'll just use this version. So, there's the starting state. Move zero is left. So if we say show grid but we're going to move passing in state zero and moves zero we should get [laughter] okay so I was going to mention this. So this is where your indexing
1:36:24is tricky. So you might just want to go back to where you were with the indexing. Um or you could turn them into tpples. Um
1:36:42yeah, I I like doing it explicitly because then I think we had some versions where we were passing in the list of lists rather than numpy arrays anyway. So we said um new r new c is equal to.
1:36:56So what happened to jonno there is that the the numpy indexing is quite powerful and then depending on whether you pass in a list or a tpple or an array it behaves in totally different ways. Um ah I've also broken it in that um we've modified the uh Whoops.
1:37:25Okay. So uh I saw something weird when I tried to apply my move and then I looked at the original one and because we had the preview function I can see this is not the original one. Um, so something's gone wrong. And the thing that's gone wrong is kind of interesting. Um, our states here is a list of numpy arrays. Um, which there's what it's supposed to look like.
1:37:51Um, we are passing modify it.
1:37:55Yeah, we're modifying this s that we get passed in.
1:37:58And um, we've passed in something called a mutable type. So, when I did this before, I was passing around strings and and having a glorious time. But I guess um Jeremy, what's a what's a nice fix to say I don't want to modify the original like root thing?
1:38:13I want to make a copy of it.
1:38:14Fix would be just Yeah, you can use um copy.copy um or numpy actually has a dot copy. So you could just put a doc copy at the end of your
1:38:36I'm going to use um copy just so that if we do have some stray strings we should be okay. Okay. So there's grid zero. Um now let's try our move state zero.
1:38:56Um okay. Hey, we moved to the left. um moving to the left isn't correct, but at least it's progress. I'm going to go and try our um our game here and think why on earth it isn't moving. So, when I click on a button, I want to go to apply move, give it the current state and the direction and target the game, which is this thing that contains the um the preview here.
1:39:24Oh, I know why he says target the game. Like he didn't mistake his uh BSS selector variables. Okay. So, and you would be able to see that if you went into your JavaScript console, it would have given you a um target error.
1:39:42There you go. Amongst other things.
1:39:43Jono, given the time is getting a bit long, should we like skip ahead a bit and maybe show us your kind of final solution or Yeah, that that's a good idea. Sorry everybody. I I um but this is great. I just um Yeah. No, I I I think the web app part um Okay. Yeah, let's let's run all here. So very similar to before, I have a version
1:40:11of the game which has move buttons which um call apply move which just shows the result of applying our move function. So if I run everything up to here um then moving does nothing. When we say let's move the robot then moving the robot works but it just eats everything reinvented back. Um, great.
1:40:39So, just pull up to the the code again. I just want to make sure people see that. So, when you're clicking that button, it's returning a whole new game state and it's replacing the existing one by targeting the game ID, which is what you've got for your game. So, it's going over the network. That's really nice.
1:41:01Yeah. Yeah. So, really useful to start building intuition. Um, and so all of this to say we we do all this setup, we get to the point where we can start to then focus on the core. And the core is things like um if it's empty space, the robot is allowed to move into it, right? So if we now move around, you didn't have to reload or anything.
1:41:23That's really cool, right? because yeah, it's immediately like and I actually put it so that if it was something that we hadn't handled yet, like a wall, it should tell me.
1:41:34Um, so then, okay, what if it's a um wall? Well, we actually just do nothing. That one's easy. Um, and so now that you have this like test bed, you can start to see, oh, right, now I see what I should do.
1:41:46So, you're still writing just one or two lines of code at a time. It's just that you're adding them to the code.
1:41:52You could also refactor it out and bit small, but this works fine, too.
1:41:56This this this could all get shrunk. Um here, like I want to test now, what if there's multiple boxes in a row? So, I've made a little grid with multiple boxes in a row. So, then I'm like, okay, what if I check along that direction, right? Which is going along the row or along the column in the right direction.
1:42:13What what do I eventually get to? And in this case, I eventually get to an empty space. Um okay, I I asked for some input and it was too helpful, so I quickly hid that. But um [laughter] you know, we're slowly like figuring out our our algorithm that they describe here of if there's a wall in front of us, the robot can't move. If there's empty space, it can move. If there's one or more boxes and then empty space, it's going to push all of the boxes. And so then it's like, okay, solve it. What's a nice way of moving a chunk of boxes all
1:42:42at once? Because I could just go like four step in direction dot dot dot. Um, so this is using that that kind of trick numpy trick where it's moving a whole bunch of things at a time.
1:42:54Yeah. Everything very nice from this start to this end. Um, and yeah, I don't know. It it the colon dr it's um adding the direction each time, which is not sure it's something I would have thought of. That's really neat.
1:43:18Um yeah so if the um direction is minus minus one there you're going to get your increments and if the directions are actually oh right yeah the directions are 2D but it's numpy so it's yeah just beautiful yeah yeah um okay um yeah so to step back we we spent all this time on the visualiz ization
1:43:46and the prep. And then we pulled out all the pieces we could getting the robot location, getting the direction, checking along a line, um, plotting, showing, mapping, all of that.
1:43:58And then we could take our core piece, which felt like in this case it kind of had to be at least five or six lines long or at least eight lines long. And they were hard thinking ones. Um, but because we've done all of that pieces, we have a test. We can check that the test passes. We have a little UI where we can say, you know, okay, I can't move left because there's a box there, but I can move right, but move down and move all the boxes. Fantastic. You know, so you can really like start to what if I try and move into a wall? I can't move there.
1:44:25Um, it's like, you know, when I'm mostly awake, half an hour of investment up front. And if this is something important like model training or you know some key piece of business logic having some tests and some plots and some ways that you can see is it doing what I expect? Do I even know what I should expect once you can click around oh I'm accidentally overwriting all the boxes. Um yeah very very valuable technique very worth spending some time.
1:44:52And also a trick is um to watch it to watch an animation of all that you can use a special thing. Have you got it actually if you'd already done it? You can use hx load to call. So you can return a something that contains an hx load which means hx trigger equals load and it'll automatically reload itself. Um um yeah. So we start at the beginning.
1:45:22Mills. Smart. Yeah.
1:45:24Yep. Exactly. And so um okay, fair enough. Um, just going to restart and run all. Um, so rather than when we click a button doing something, we can set a trigger on the thing to say once it's loaded after a delay. Sorry, apologies for all the scrolling. Um, once it's loaded, after a delay, trigger the action to hx get, which is the same thing. So, it's going to keep replacing itself with the um the updated version.
1:45:56Um, yep. Here we go. And you can see the little robot moving around.
1:46:02So, these are the actual commands that it um they give you 20,000 of them. So, it's going to take a while um [laughter] potting this way, but this is because we've got this delay and this network loop stuff.
1:46:16And so, this is there. There's no animation library. There's no canvas. There's no, this is just literally outputting a bunch of In fact, do you want to go into the um network inspector tab uh dev tools?
1:46:33Sure. It's going to uh pull up fairly quickly, so I'll stop. [laughter] Yeah, there's um every 50. Yep. They're just uh they're piling in.
1:46:47Um that's so cool.
1:46:49So yeah, that was fun. Jeremy said to me, "Oh, you should animate it." Okay, cool. Um, good idea actually. Um, obvious idea in hindsight. Um, yeah, Jonno, we've got quite a bit more still to cover, so we're going to go a bit over today. So, I think we should have a second five minute break if that's That sounds good.
1:47:06Okay, a good plan.
1:47:06All right, see you in 5 seconds. Five minutes.
1:52:19Is it 5 minutes? I can't not quite sure. I think it is about right.
1:52:23Yep. I think that's about 5 minutes.
1:52:25Just enough time to pop some pean pies in the oven.
1:52:31I will have an Australian pie today to celebrate. Um, nice. [laughter] Um, I want to show something I think is kind of interesting. Um, so
1:53:11Folks out there might have noticed we have a new delete above button in addition to our old delete below button. Um, and it uh has a couple of extra things about it.
1:53:29It's got a little very of red to indicate this is a more dangerous than average button. Um, you might remember the old delete below button was different. It had like a cloud and a lightning bolt and a downward pointing arrow. Um, so when I went in to find the there's like a database. Yeah, it's like this. Oh, that's right.
1:53:57I didn't even have the arrow. It was just database zap. I tried to find something that looked like it was going to kill things. Um, and so I looked around at zaps and there's no like zap to say zap above or zap below.
1:54:10Um, so normal people, god bless them, um probably would have stopped at that point and just been like, "Oh, I don't know. We'll just pick an arrow that happens to exist." There's plenty of arrows in um Oh, not that button. Okay. Command shift t in zoom I have to turn off because it doesn't reopen a tab. Um it says p pause pauses sharing.
1:54:35Um so there are certainly plenty of arrows that go in different directions but um none of them were quite what we wanted. So yeah we were like okay we'll um we had already decided to write our own lucid icons library and this is our third attempt at writing a lucid icons.
1:54:53Um, the first one was by me and it was such garbage I really wanted to throw it away. And then Isaac reused the Franken UI one which actually grabbed the entire Lucid icon library which is absolutely huge and dumped it all into a single JavaScript string which I thought was horrible. So then this is our third attempt.
1:55:18Um, so I've already put quite a lot of work into just displaying icons. it's surprisingly difficult to get right. And then I did a fourth attempt of this where I learned about sprite sheets and made implemented this with sprite sheets. And then Nate came up with this really [clears throat] ingenious idea of like, well, what if we could have something that combined SVGs? We could then have an arrow, you know, on top of a zap and we could pick them. And so if we could combine SVGs, wouldn't that be cool? So then he wrote um an
1:55:45implementation of that um which this is all open source so you can see it. Yeah, here we go. So I merged it with some enthusiasm.
1:56:02Then I kind of read through code and started to use it and then I was like no I don't like the way he's done it either. Yeah, this is like you have to be like, you know, uh to kind of have this taste or whatever, you've got to be prepared even for your own colleagues to say like, "No, this could be better." He kind of it relies on having colleagues like Nate where when you say, "Your word work could be better. I've made it better." Their responses were like, "Oh, that's awesome." Rather than you bastard, you
1:56:32hurt my work. you know, um, and Eric Reese is probably going to talk more about this, right, of like how do you try and steer your organization towards that being a culture and how important it is to set those goals.
1:56:45Um, otherwise it you do default to not doing that.
1:56:49Yeah. So then I spent like all day on it [laughter] and um very much like okay, I can see why I don't like Nate's thing because actually it's just difficult to do, right? And so then Ren's who's Dutch so he came at the end of my day turns up in the voice channel and says like how are you doing?
1:57:08I was like miserable. It's terrible. I hate my work. This is crap. And he and again he looked at it and he wasn't like no don't worry Jeremy it's lovely. He was like that is crap. Why don't you just do operator overloading? I was like be so hard to do operator overloading.
1:57:23I'd have to do this then I'd have to do this. Then I'd have to do this. Then I'd have to do this. Then I'd have to do this. And only then now you see it works. It's like, oh, we just did it. Okay. [laughter] Um, and we ended up with something that I think all of us are quite happy with. Uh, if I can just go back here and click here.
1:57:46Um, with operator overloading, you just go circle plus an X. Ah. And it's like, okay, as far as I know, we've invented something. I don't think I don't know, maybe there is. We didn't look care that carefully, but as far as I know, this is the first SVG library to support the addition operator.
1:58:11Um, it also supports um plus equals by the way. Um, and so after all this, we are finally able to bring you the delete above and delete below with custom fills and translate. uh on each one. Uh anyway, so that is just a little passing thing. Um and what I actually
1:58:39visualizing a bit of code with fastly side for homework [laughter] totally as one single icon.
1:58:48All right. So, I wanted to show you guys broadcasting. And actually, [clears throat] just to jump ahead a bit, I'm actually not going to show you broadcasting. Uh, I'm going to try and get to a point where you're going to teach yourself broadcasting. Uh, so again, all the interesting hard work I'm leaving to homework and getting you into a place where you're ready to do it. That's my goal here. Now um broadcasting is one of the
1:59:16most important concepts in AI in machine learning in high performance computing um and uh in what Iverson's truring award-winning lecture describes as notation as a tool for thought when you can think in terms of broadcasting you can concisely use notation just like polia wants us to do to to clearly describe um the problems you want to solve and to solve
1:59:44Um so broadcasting um okay so we've already got numpy so broadcasting as we've kind of seen well we start with element wise operations.
2:00:07Um so that's basically what element os operations do is they add the first two things the second two things the third two things and they do that extremely fast and uh you could also do that um with pietorch if we said torch.array sorry torch.tensor instead of mp.array array do the same thing. Um, and if you put CUDA after that, you have a GPU, it will run all of those operations in parallel potentially billions and billions per second um, for you. Um, and
2:00:36as Treto kind of showed us earlier, you can do that adding a either a single element um vector to a vector or even a scalar and it broadcasts this across this. You can [snorts] broadcast rows over columns, sorry, rows over matrices. Uh there's all kinds of stuff. This is kind of the workhorse of
2:01:04the linear algebra that we tend to do um inside deep learning in particular um but comes up all over computational linear algebra um for which uh Rachel has a complete course which I highly recommend for anybody wanting to go very very very deep on this.
2:01:25Oh, I'm glad it's one of the top things that people search for. Um, so this is a really cool course. It's one of these things where people like, "Oh, 2017, it must be terribly out of date." Let me tell you something. Linear algebra doesn't go out of date, [laughter] right? This is totally uh uh current and stuff that if you want to go super deep, it's well worth knowing. Um, if it wasn't, we wouldn't have taught the course.
2:01:52Um anyway, I'm not going to use any of those things because why would I teach you to know do something I already know how to do. Um instead I decided to use Tiny. Um so Tiny is one of the two most interesting um uh systems around for um massive linear algebra calculations nowadays. The other one being Mojo.
2:02:16Um I won't go into too much detail but basically they both have proper compilers um and they create a fast um implementation of your um [snorts] neural networks or whatever it is that you're doing. Um they work uh very fast on CPU and very fast on GPU as well. Um so I've never used it before. So, um,
2:02:45originally I actually asked, this is shows me how little trust I have, I'm sorry, for our systems. I actually went over to Gemini 3 and asked it to um, carefully research the latest tiny docs, prepare a detailed markdown, consolidated documentation on the API, have every function and method, parameter details. Uh, this is going to be for LLMs, not humans, so make it concise.
2:03:10And it did. And uh kind of new thing I've realized um partly thanks to actually um Discord buddy pointing this out. This is a great thing for using raw um type instead of note type because you don't really want these headers and stuff to appear. You don't want if there's a dollar back tick to mess anything up. So I just dump it in there as raw. Um and it did a pretty good job.
2:03:35And then I thought like wait, we have opus, we have tools, we have research at home. So I just went above that. So I didn't have it in um in uh context and said exactly the same thing. Um and it went off and started reading URLs and doing [snorts] searches and created its own um yeah I started looking through this
2:04:03and I was like that actually looks pretty good. So then what I did was I um I always think the best way to find out whether an LLM liked some piece of information is to ask it. So I just said compare the Gemini 3 results with your own results and it said like oh well I actually had lots of things that Gemini didn't have like oh well there you go. So um that's given me a lot of trust in actually solve it as a research platform.
2:04:30Um so I might even just delete that one. Um, so a good way like how do you learn a new system? Well, actually Tiny Grad's great about this. Their docs actually recommend checking out the Tiny Grad puzzles. So there is a um set of puzzles created by Sasha Rush who's a fantastic researcher um to teach um did he originally do it for CUDA? No, originally for PyTorch, I think. And
2:05:02then um our own um Sarah and Austin created the GPU CPP version. Uh that's the one top top link there.
2:05:19GPU puzzles. Thank you. Um so there's you know so we're all kind of now using Sasha's great work and so then yeah there's a tiny grad version. Um, so yeah, I just went through and I followed the documentation uh and tiny grad of how to install it, which is to do a git clone and then pip install- dot. And then this one here says do a pip install-r requirements.ext. So I cloned this and I did that.
2:05:48[snorts] Um, and um, I also just popped the readme for the puzzles in here. Um and um this is actually let's see where did I end up with this I had a reposh
2:06:24yes so I cloned it into tiny grad tensor puzzles and then I just opened up puzzles Um, okay. So, this is their puzzles. Um, and their puzzles start out with like this this thing, draw examples.
2:06:52Um, and I was like, uh, that's not very nice to read. Um, so I always liked everything to be good, you know. So I then used our trick of question mark question mark um to find out what draw examples does and it calls underscore draw example. So then I was like okay have a look at that. Okay. And I was like um like okay just tell me how to make them a lot smaller. Um so I kept on
2:07:20digging into the various source codes and asked it and it gave me a fixed version just like okay that's nice. So again it's like if something's not right fix it. you can then upstream it. So I told uh George Hutz about our fixes. Um so again actually that's an interesting thing worth mentioning.
2:07:38You know when you're learning something new I discovered that there was a learn tiny grad discord and I went in there and I asked about some questions I had and people started answering me and I was like okay this is my summary. And then George Hutz came in and confirmed like yes your suggestions would be improvements to our documentation. let's fix that up. And, you know, asked a few follow-up questions and George came back. And, you know, people who make these things want them to be good and they want people to like them and stuff.
2:08:08So, it's worth getting involved in these communities. Um, um, yeah. So, they're kind of just, so this is me just learning how their system works. Um, and so then I Okay, so they've got like range three. So let me just run up to there.
2:08:33And so the background like the the visualizing in there, Jeremy, this is like you just making as ergonomic as possible an environment to work in, right? It's like Yeah, exactly.
2:08:42Loading up the sample data and Yeah, exactly. So this is what happened when I when I opened up the notebook they provided.
2:08:48I mean, you can see it. It's like it's not great. Um, so yeah, I want it to be nice for if I'm going to spend time on this. Exactly. Um, and you know, you can see like when you do range three in Python, it doesn't actually show you range three until you listify it to find out what's actually in it. And the same issue in um the the equivalent in tiny is a range three and it doesn't actually show you
2:09:18what's in it. It just tells you it's a tensor with three elements that they're integers and it's on a GPU and it doesn't have a gradient which is not actually what I care about. So um I happen to know that you can add a markdown representation of anything in ipython or jupiter or solver it by creating a particular function. So I created that function and now when I run a range three it now oh prints it out nicely. You can see it's very simple
2:09:46right? I just return a fenced markdown block with its converted to numpy version.
2:09:54And again, you know, George replied to me and said like, okay, I definitely want to add this to tiny so in the future people other people will have this same thing. So also if I print it, it calls done to stir. So I decided to just print out the list. Uh so I'm making it all nice and um no one had ever done this before.
2:10:14like I had it done in the first 20 minutes of looking at it, but like everybody else is just like, "Oh, I guess that's how it is." And you know, George said to me like, "Oh, you know, I'm kind of embarrassed about how crap it was. This is great to fix it." Um, and then same with like when they're creating tenses, they've got all this like tensor square bracket thing, which I thought was kind of ugly. So, I just added a thing called T that doesn't need the square brackets to create tenses. So now I can create
2:10:42and display tenses very easily which is nice. Uh so the next example they had was showing how where works and I was looking at this. It's like gh nasty. So I just told it make it t. So it's already getting clearer.
2:10:59Um and then try to make it a bit easier to see what's going on. And so yeah, so I don't know if other people find this as difficult as I did, but I had a lot of trouble understanding then what what they're trying to show us here. So they've created these various examples and then they show there's so there's there's no text in the just as you can see this is just literally straight from there example
2:11:28doesn't tell you anything about what this is meant to mean and I didn't get it. So if you all get it easily, don't tell me that's embarrassing. But if you also don't get it, um, great. Um, so I started asking it like what what is this? What are the colors mean? Why how is it setting them? Why is it setting them? Um, and so because I already had like this underscore color, it was able to kind of like tell me what the different things
2:11:55mean. Um, which was nice. Um so what I eventually discovered was um yeah um each column is one of the examples. So Q I don't know why they call them QA and B exact. Oh I guess I do. That's Q where has QA and B. So I'm not going to teach you how wear works but you should definitely learn it. It's really really useful. A very important piece of all kinds of high performance programming.
2:12:26Um but in this case it's showing if false. So false is represented as white. Um and uh orange is positive. So in this case it's um true. Um so if Q is false and A is 10 and B is zero. This is actually doing exactly the same as um a if b a if q else b. That's what it that's what where does but it does it
2:13:01for every element of the input.
2:13:04Um so an example would be like my I wanted to look at my grid and see where it was the robot character.
2:13:11You could say all the boxes with this.
2:13:14My boxes are everywhere. Yeah.
2:13:16Yeah. So here Q is false, true.
2:13:21For the second example, A is one twice.
2:13:27B is -10, 0. So blue is negative. And it's going to be darker if it's a higher number. And so the first one because it's false means it'll select it from the second one. So you can see the return value is blue. And then here we've got a true which means you select it from the first one. So I'm not going to go through all of this but this is using also broadcasting across multiple dimensions. This is like this this is one of these things where
2:13:55some things in life are worth studying extremely closely like not many things honestly. There's a lot of slop AI or human u or like business books which you know 500 pages that could have been three pages.
2:14:11This is one of those things where if you study this for however many hours it takes with solv and have it check your understanding by saying okay test me if you can understand this you've you've learned a huge amount. So that's the piece of homework number one is understand this fully and have solve it test you um okay so then it has puzzles.
2:14:40All right. And the puzzles work like this. They make a test. And again, there's no there was no information. So I had to figure this all out yesterday. Um so they create a test. It has a name which is just what's printed. Um the spec is the answer. So the answer is that if you go through the whole answer, every single one should be one. Um, and so that's what a test is.
2:15:11And so then the answer is whatever happens when you call once. And so it raises not implemented error. So currently this test is going to fail. So if I call uh I think you just called it right.
2:15:26Oh, and the the falses there mean that you failed on all of those cases. Is that what that orange upper?
2:15:32Um, no. This is showing me the target. So the target is should be one one one one. So you you actually have to run um run test run test ones.
2:15:56Okay. And it says failed falsifying example. So I I learned a bit about it and apparently it's using this thing under the hood called hypothesis that creates random inputs and tests it on random inputs and so it's come up. It tries to find something that fails. So it failed and of course it failed called ones and it says not implemented.
2:16:19So this is basically how the system works. So I was quite interested in it and I'll show you something super fun.
2:16:24Um I don't know if I've shown you this before Jono. I was wondering like what the hell is this you know and what the hell is this?
2:16:32There's a lot going on, right? So, there's a lot of quite sophisticated programming in Tiny Grid.
2:16:37And and Jeremy, just to emphasize, like you're you're saying, "Wow, there's a lot going on." I can see a few people in the chat saying, "I definitely don't get it. There's a lot going on." Um, you're not meant to get it. This is the homework. This could take this could take you weeks to do this homework. Do you know what I mean? Like this is one of the things I'm saying like like really spend time on this because if you get it then you've got a fundamental a number of fundamental building blocks of like linear algebra, AI,
2:17:06high performance programming.
2:17:09Yeah. Yeah. So don't be one of those people who sees something hard that you don't know straight away and says like, "Oh, I'm not the kind of person who can understand this. I'm not clever enough.
2:17:20I give up." You know, like Jonno and I both spend hours, days, weeks, months. You know, Jono and I did this whole diffusion course where we spent like half a year trying to understand diffusion. Like, yeah, it's okay for things to be hard. Um, none of us find it easy. Just some people are tenacious about keeping working on it.
2:17:42So, keep working on it. Um, but I just want to show you this cool thing. Um, so I wanted to find out what ad sizes is. And I was sick of con continuously typing every you know um question mark question mark for every damn thing. So I created a tool where you pass in for example add sizes.
2:18:02It looks it up gets the symbol and gets the source code for it. I then passed it to solve it and I was like oh what is add sizes? So it went ahead and got the source code for that and it got the source code for that, right? Um and so with this tool now it can agentically explore an imported codebase.
2:18:28Um and it went ahead and told me what the hell is TT, what the hell is ad sizes?
2:18:35Um it's like I still don't get it. So like I kept asking um I was like, "What the hell's this puppy reward?" I knew there was something interesting coming up at this point. [laughter]
2:18:50Um, so yeah, um, this is where it told me, oh, this is this thing called hypothesis, and it's going to do a whole bunch of like tests, and this is how hypothesis works. And it's like, okay, this is this is great, you know? And so for stuff like this that's very concise, it's kind of a classic style of folks like George Hutz, right? And I think it's a I don't know if it's intentional, but it's almost a kind of gatekeeping. I think I sometimes heard him talk about
2:19:19this of like, look, I I I want things to be a little bit difficult because I want to see that people have made an effort.
2:19:24Um, so we've got we've now got a system that can break down all gates with enough time. So, um, you can take the effort to understand it. Um, so here I started looking, yeah, trying to understand it and I kind of eventually got got the hang of it. So in the end I just wrote ones and it returns tensor ones and it returns I of them. It makes them int32s.
2:19:50Redid the test and now it says okay this is the target. This is yours. It's like oh okay for that example it worked. So I ran the test and I discovered why it talks about puppies because I it gave me a video which was very adorable. Oh. I wonder is random. I don't remember this particular video. Anyway, no.
2:20:17So, puzzle two. So, I've got the solutions to the first three. So, puzzle two um was that it has to match the same as going through the whole thing and adding it all up. Um, and so you should figure out why this is the answer. Um, and so it shows me here's the input, here's the target, here's yours. Okay, it works.
2:20:42Um, and I was kind of wondering what the hell these things are. Like why are they there?
2:20:49Um, it's like lots of information. And I thought these two square brackets seems unnecessary. Why would you have two square brackets and there could be one? So I was like, what's with the extra square brackets? And it's like, well, here's the reason. It's like, well, that seems dumb.
2:21:07You're absolutely right. And I was right in fact, you know. Um, so I was like, okay, and again, it's using my tools, right?
2:21:16Now that I've given it its tool, it can just go in and read the source code for me. Um, tell me how to fix it. Um, and it's like, oh, that looks right. And so, again, I showed this on Twitter and people were like, that thing's been driving me mental, too. It's like, okay, well, I'm the first person to spend five minutes fixing it. So, now you only need one square brackets, but two also work.
2:21:41So, um, ran the test.
2:21:49[laughter] That's They figured out a good a good motivation. I would do a lot more puzzles if this was the reward.
2:21:57I know, right? [laughter] Uh, [clears throat] okay. Now this is the real homework, right? Outer product. So outer product means um take each of these and put them down the side and take each of these and put them along the top and then in the middle is each of them times each other. So like a a times table for example. So your primary school kids um actually let's do all of them bigger.
2:22:38This is an outer product [snorts] of range 13 by range 13 because each each vector is along the top and the side and in the middle is each one multiplied by each other. Okay? So we don't call them out of products in primary school but that's what they are. They come up a lot. Um not just for times tables.
2:23:07Um so this one was um go through each of the first one go through each of the second one and calculate them multiplied by each other and put them in that spot. So that's outer.
2:23:23So you have to um implement outer and so I then went up and said like okay well is there an outer because it had all that nice documentation I gave it was like no there's no outer unfortunately he gave me a tip as to what to do but that's okay didn't do it for me. Um it's like you don't need outer you can use broadcasting.
2:23:46Uh, so I played around with shapes, tried it with my little examples just like Jono had, right? Little examples, saw it was working and I put it in. This is the answer, right? But this there's so much in this line of code. Um, so what I want you guys to do is like again like really understand this and then make sure you could recreate it.
2:24:18And Jeremy, why? So def outer, we have the outer spec there that looks like it does what we want. So when we say implemented, could you could you copy and paste that?
2:24:32Yeah. So, what what is like maybe what's the goal or is there a reason why we're trying to do it a different way?
2:24:39Well, um that would be cheating. I mean, a that would be cheating to just [laughter] take the existing answer and be like, "Oh, I solved it. I copied out of spec." Or you could actually say return out of spec.
2:24:50Um um but you know, the real reason is you're meant to do it with um tensor computation. Um and in fact they might even let's have a look at tiny grid tensor puzzles. [snorts] Um it's tempting to find a magic function for everything but actually the tensor APIs are really expressive. You can do most things from first principles and clever use of broadcasting. Um and so you can also look at the original version.
2:25:22Um like chess puzzles. This is practice in a simplified environment. Um, these puzzles are about broadcasting. Okay, look, there's a picture of the rule. So, you guys are going to have to come and study this rule, learn this rule. Every puzzle has to be solved in a single line of code. Um, this is all you're allowed to use. You're not allowed to use anything else.
2:25:55Um, oh no sum. I guess that means I cheated with my sum. Interesting. [snorts] Um I didn't read the rules carefully enough. Um so that's one reason is it's against the rules. But the why why are those the rules? Well, because if these were both uh 15 billion item GP uh GPU arrays uh vectors um then running this code would take 225 quadrillion couple hours, [laughter] you know. Yeah.
2:26:24Yeah. Um this code here would take like a billionth of a second um because it would do all of them at once. So yeah um this is this is how you have to write code you know to do things on GPUs uh at at high performance and yeah um this is programming is increasingly moving in this direction. You know, a lot of programming is basically linear algebra nowadays.
2:26:49And so like advent of code would be, oh, I'm I'm passing different types of strings and I'm doing cool algorithms on those. This is like, okay, I'd like to get better specifically at the things that are good for GPUs that would be good for deep learning.
2:27:03Uhhuh. Yeah. And a lot of stuff in advent of code, it's quite fun to be like, okay, let's try and use the tensor puzzles restrictions like can I can I do this with numpy? Can I do it with broadcasting?
2:27:15um quite a lot of it. You can you could even ask solver it like okay I solved it we had what do we have 63 lines of code gosh you know would numpy have maybe helped us torch maybe helped us um it can be yeah worth exploring cool all right that's our longest lesson there we go yeah longest definitely a dense one but um and oh why use tiny grad rather than pietorch
2:27:42probably you don't I mean um but it's it's It's one of the two kind of emerging systems um that are definitely underneath much better placed than PyTorch is probably to be the the future of how this kind of stuff's done. Um, Sunnith Gentel, the co-author of PyTorch, has been expressing for a long time his kind of dissatisfaction
2:28:11with basically everything including PyTorch nowadays. You know, sophisticated stuff like, you know, flash attention and things like that are always written basically in C++. Um, and everybody's trying to find a better way. Um and so this approach of of um having compilers that work on well- definfined languages seems the right approach. Um so but you know feel free to just do the pietorch
2:28:45um puzzles instead of the tiny grid puzzles. They're uh all great ways to learn this. Tiny is just a interesting newish thing that you might enjoy playing with and great opportunity to uh contribute to a new growing community which is going to be increasingly important and they've got their own Discord and clearly as we've seen George is helpful and responsive.
2:29:11Um which is funny because he's quite a well-known guy in the community and everybody's like oh my god that guy is such a rough dude and it's like no he's just a programmer who like working on his stuff. So, you know, [laughter] uh he's the creator of Kama AI, the self-driving car system. He was the first guy to what was it? Um unlock the iPhone. Interesting background. So, yeah. And he's uh I always like to work on stuff where people with interesting
2:29:41backgrounds are doing work. So, Chris Latner, Mojo, George Hotz, Tiny Grad. Getting involved in these communities early is often quite a lot of fun. You can often learn new things and very interesting code to read often. It's not just like the same old boring stuff. Yeah.
2:30:00Great. All right. Well, next week, exciting week, Eric Reese. So, tune in then. Um, and that'll be less technical homework, I promise, than uh understanding broadcasting. So, you'll have plenty of time to work on that. And also, Advent of Code, keep an eye on the Discord. We'll make new channels for the challenges as they pop up and we can discuss and share spoilers and um see how everyone does it.
2:30:21Cool. Thanks, Jeremy.
2:30:22And it gets harder and harder. So, try to do the pairs of puzzles at the start because later on you might want to have more time. [laughter] At least that's my experience. Bye, everybody.