Transcript for:
Learning Julia Workshop

yeah so welcome again um to learn julia with us i'm kyla and this is yulia we are the um two kind of leaders of this workshop and we called it learn julia with us for a very purposeful reason because we are also learning julia and uh julia and i um wanted a reason to stay motivated with learning julia and so um that's why we got started with this so today we're gonna do the very basics of julia we want to start with telling you about us of course who we are and what brought us here we want to ask a little bit about you and just get an idea for the group and what your needs are or your desires we want to talk about julia the language why we think it's great and then we're just going to show a few basic things about getting started with julia including um installing it working in it's in the julia console and working in a couple of different environments with julia and then so the nitty-gritty of the kind of coding part we're going to start with a little bit in our upcoming events so we are doing this once a month always on a thursday night at the same time it's night time for us um the next one will be on march 17th then we have one on april 14th and may 12th so those will those are all already scheduled on our meetup page but you'll get a little reminder about them when they're announced and we have kind of a vague idea of what topics we're going to cover but some of that might change so um we're basically going to take it at a pretty slow pace a very easy you know if you have a master's thesis in software engineering and julia do in six weeks this might not be the course for you we're gonna take it you know nice and relaxed through getting acquainted with julia yeah so who are we um i'm kyla of course and this is julia you can call her julia or julia i call her julia because um she's german and it helps us distinguish between julia and julia the programming language and we are two phd students we both do linguistics and we're located at the university of freiburg in germany so for those who don't know fryeburg we're right down here in the southwest corner um quite close to both france and switzerland in the black forest region of of germany and julia and i are big fans of the language are that's actually where we got started with doing this kind of workshop um we co-organize our ladies freiburg and we do events workshops kind of like this one except for on topics related to r twice a month um there you can look us up if that's something that you also are interested in um but that's really what brought us to this style of workshop because we really love doing this kind of community teaching and learning together and we have recently discovered the joys of julia so just in the past um year or so so we generally use julia for academic research um and we use it for modeling so fitting bigger models that we could or more complex models and is easy for us to do in our so that's how we've gotten into julia but we are excited to learn more julia together in this group yeah and so we have previous experience in r we also have experience with python and we are looking to grow our julian knowledge together in this and we have we're going to be using a lot of the resources that are available in the juilliard community for that yeah so now we want to know a little bit about who is here tonight um i'm going to pause the recording uh thank you for the yeah thanks for participating and we'll restart the recording now yeah great so we saw that we had a lot of um a lot of interest in julia we have a group that has you know we're just getting started and that's really perfect so i'll tell you a little bit about julia and um kind of why we're interested in it and julia is a general purpose programming language so you can use it for a lot of very diverse applications but it's popular in the data science communities and we saw from the group that there's a lot of interest in data analysis um in academic analysis or different types of data processing applications and this is perfect for dualia because julia was built with data science and machine learning in mind so while it can do a lot of other things it really has a strong basis in in these topics like r and python julia is free it's open source most of it is hosted on github and packages can be contributed by the whole community and it was developed to be readable like python so the syntax is pretty easy to work with but it's compiled really quickly so it has comparable performance and in some cases even better performance than some of the lower level languages like c it's a young programming language i think it just turned 10 years old like this week or last week uh which in comparison a language like r is about 30 years old uh we have a little note with the the julia community prefers you don't gender the language julia so just call it the julia language or it don't um try not to use gendered pronouns for it but yes then i wanted to show just a couple this is a little some benchmarks from the julia website and my um formatting got a bit off here but basically there are little benchmarks that show the performance of different programming languages so right here we have julie on the left and r and python are over here on the right and there's a couple other languages mixed in here too so you can see because this is in scales of order of magnitudes that julia is way faster than r for example i don't know if that really surprises that many people really surprises you your user of our mate does not surprise you at all um and it's also faster than languages like python so it's really fast like i said a moment ago it's really readable it also has a strong emphasis on reproducible methods or environments that you can use julia in that make it reproducible for example in an academic context if you want reproducible research on the data science side it can handle really complex models it can handle really a lot of what you throw at it and julia is really easy to integrate with other programming languages so there's a lot of packages that will make it easy for you to use some of your favorite features from our python for example so um before we get to working with julia i want to give you a moment to install julia if you don't have it installed yet so you don't have to have it installed yet um and so for this we're going to go over to the julia website what you can see here is just julia lang.org and if you go over here and under downloads if you go to julialang.org you land on the julia programming language homepage and um up here on the top bar we have download julia and downloading julia's relatively straightforward as far as we have seen so far but let us know we're going to stick around after the talk if you have any problems with installation but hopefully it will go easily and you can pick so all you do is pick your system from the list here and then you download the installer so for example i'm on a mac i would download this dmg file and there's also a help page if you click on help so for example here for mac it lets you know that you install julia just like any other mac software by dragging it to the application folder and then you can open it from your applications list and i believe julia here is on windows is there anything special to say about windows well if you click on help next to windows um as well so for windows you just download this installer you save it wherever you like and then you execute it it'll run and then one thing i'd like to point out here is for windows that there's a screenshot here this is what the installer is going to look like there's two options um creating a desktop desktop shortcut or start menu entry that's kind of optional that's just if you want to find it more quickly but the third one you have to you should tick that um so add julia to path so that's essentially going to prevent a couple of problems from from occurring or potentially occurring later on so that's always a good idea to take that straight away and that's pretty much all you need to know and then the installation just runs as you would install kind of any other any other program or any other app and we'll show you how to start and use it in a second yes exactly so and i think the mac has an optional instructions here also for adding julia to the path so that's something you would have to do um in the command line you don't need to do that to work with julia in general but it's like yulia said it's helpful for other applications or might prevent some problems great okay so um maybe we'll just pause for a couple minutes here and let you get installed maybe let us know in the chat if you have it installed or if you're if you're working on installing it and we'll just pause for a moment um if you've already installed that you can you know get a grab coffee real quick and we'll we'll reconvene in a couple minutes we need help later okay so now we have julia installed and um i wanted to have both these windows open so hopefully it's not too confusing that you see my video here but now if you have it installed you should be able to find um julia in your program list so here uh is the julia logo from me and when i click on that i get a little terminal application i want to show this and okay so i get on mac here it looks like a terminal application um it should look similar on on a windows pc as well so it's my computer is recognizing it's after dark here so it's gone into dark mode in the terminal but you see it looks like the terminal but it has the julia logo and this is called the julia ripple which stands for the read eval print loop or evaluate print loop this is your most basic way of interfacing with julia so this is the way this is the kind of lowest tech um most direct way to work with julia on your computer you can see there's you can probably already see that there's not really that many bells and whistles but this is how it comes installed on your computer there's several other ways that you can work with julia and some of those will show you in a in a bit so yulia will show you a couple of different ways but i'm going to show you the most basic way first you might also see if you work with julia with other people you may see the form of a julia script which is generally a file that ends in jl there's julia markdown files which combine text with blocks of julia code those would be jmd files and there's different ides which stands for interactive developer environments that you can work with it in that would be something that gives you a few more benefits like they might have help they might be able to help you debug or you might be able to test parts of your code um or might give you some help with syntax so we'll show you one of those briefly and then what we're going to be doing for most of this course is using something called a pluto notebook and this is um in some ways one of the more one of the higher tech more bells and whistles ways to work with um julia and it's great for teaching but also for doing reproducible reports because you can combine text with blocks of code and you can run single lines of code and see the output of them immediately right next to the code so we'll look at that in a moment but just a preview of what's coming but like i said i want to start with looking here in this julia rebel um and i don't know if i'm going to be able to make the text on this figure oh i can good just to make sure everybody can see it so you see that the line is headed with julia that tells us that we're working with um and we can do basic stuff in here anything that julia can do we could do from this line it's not something we're going to do very often because you really can only put in like one line of code and then run it and get the output it's not something we can develop easily develop an entire analysis but we can do basic things so if you open up your julia riffle like this you can try different math problems for example and you'll see of course um julia can handle any sort of complex or random math stuff pretty pretty easily there's no math problem that's gonna stump it so um yeah you can play around with what julia can do in terms of basic math and you could also run julia commands in this line when if you wanted to that would work better with things that are pretty simple but basically when you're working here it's always working in the julian language um but this rebel so this little terminal has some cool other features one of them is if you press if you press question mark so what i'm doing here is pressing question mark on my keyboard and that will enter me into the help um the help area of julia so you could look up about like if you see a command and you don't know what it means like sqrt you could type it in the help section and it would let you know that it's it returns the square root of a number and it can give you certain errors if you don't if you give them a if you give it a negative number for example and it gives you some examples so you could try you could see just all sorts of examples of what code you could give and what it would give us a return and there's a whole bunch of other information so this is a really easy way to access if you don't know um about a command what it does you can press question mark again and you can see instantly that this changes to help so now that we've learned that this is the square root for example we could try a root of ten thousand for example and we could get the answer to that so just question mark and to get out of the help section you press the backspace when there's nothing on the line so question mark backspace question mark backspace so that's a cool built-in feature of the julia rappel and reading the help pages can be kind of overwhelming like right now this probably looks a little bit overwhelming it looks overwhelming to me too and that's something that we are going to come back on over and over again is kind of practicing reading the documentation and checking for help um and finding things and finding out how to do something that we don't know in julia okay so that's one thing we can do in the rebel is we can or that's two things really one is we can run julia code and two is we can um look up the help the help documents about a command um were there any questions awesome chat activity no looking good okay so then the other feature of the raffle that i want to show you today is the package manager and for this you press my keyboard doesn't have this yeah you press the um the square bracket this this kind of i guess it's the right square bracket and when you press it on the keyboard you should instantly go into this package package manager part of the console so again when you're in the normal julia ruffle you just press this right square bracket and it should change the prompt at the beginning of the line to pkg so i put that this is also on the slides if you want to check at it later so you're in the package manager now and what this is or why we have a package manager is because the julia language has certain core components that are always involved so if you just load julia you get basic abilities like the ability to take square roots or do basic math but the real wealth and diversity of julia comes when you install different packages and packages can be developed by anyone in the community there are some that are going to be really major that you're going to load most times that you use julia there's others that might be specific to climate modeling for example or any sort of very specific application you might have there may be a package for that um and so you can think of packages as like add-ons to julia that extend its functionality beyond its core and in general julia is a language that has a relatively smaller core and is and relies a lot on packages or packages can be really that's where you're really going to get the power okay so if you're in the package manager what you can do here is add packages to your base directory um so basically to your default setup for julia you can also update packages here so when the developers release new versions on github and make official official updates to their packages you can come back over here and update your version to make sure you have all the latest functionality so how do we do that so first um for tonight what we want to have you try is installing a package called pluto pluto is the package that runs pluto notebooks which i talked about earlier as a one of our teaching resources so let's go ahead and add that you um when you're in the package manager so the line has to start with pkg then you can say add google and you can run that line i already have it um well i'll try it okay so it's going to update for me so go into your julia reppel now and go ahead and enter the package manager by typing this right-handed square bracket and then try running this line of add pluto and it probably will take a little while for this to load so give it a little a few moments to load you're probably going to get more text than me because i already had pluto and i actually updated it last night so it has no it has no work to do but um you'll probably get a very long list with some little spinners and all sorts of texts coming up that will be adding this package to your julia installation so again i'll just pause for a few minutes to let you catch up with that and let us know in the chat if you have questions and maybe one last thing to say about the repo before we carry on is that just like adding um packages you can also update packages so for example if you install if you have pluto installed and you know you installed it like a while ago you might want to give it an update by just running update pluto um and that's something you may need to do at various times but yeah so that's the rebel and now yulia's going to show you a couple ways that you might work with julia in the real world so not just in single lines in the in the terminal yeah thanks kaida um i'm going to you should also now be able to see what it looks like on windows which is not you know very different from what it looked like on mac and it sounds like you all found it but if just in case you can always click on start and then julia will be here at the top because i just installed or reinstalled it or you can also start typing to find it so just in case you got lost um there this is how you can find it and start it and i'm in the rebel first [Music] and we mentioned that there are these kind of text editors code editors like visual studio uh code and i'm going to just really quickly show you that we're not going to use it much or we're not really going to use it for this workshop we're going to use pluto notebooks um which i'll show you afterwards but you might see people using these in case you watch any youtube videos other tutorials people use visual studio code a lot so vs code is a general purpose um text editor coding um kind of editor so this is not for julia specifically i also use this for python a lot and you can use it for lots of different languages actually so i'm just going to show you that you don't need to install it i just want you to to kind of recognize it when people are using it and not be you know confused so when i start a new script here uh so this is going to be my script up here and this down here is basically our julia rebel again right so the script has this advantage that i can save what i've done so next time i want to continue coding i can return to it i can save it somewhere open it make changes add to it and so on so if you're familiar with python or ah right you'll be familiar with this idea of a script so um vs code because it's good for a bunch of different languages you can use a bunch of different languages in it will ask me to select a language so it knows what language it's in so it knows how to interpret the commands properly and to help me with it so i can select a language yeah so i can select language here i can just start typing julia it'll come up and the reason why it comes up is because i have extensions installed um that helped me interpret this julia code yeah so this is this the julia language support is what i have installed this is going to kind of try to warn me if i make a mistake um yeah that's what that's for so here in my script i can now i can also do these little math operations i can do maybe a print statement and we'll don't worry too much about what this code all does and means we'll we'll get into that next time and the next times this is just to kind of show you what it looks like and if i want to run that i can just click i can hold shift and then hit enter and you can see it puts the result in the same line and it also puts it here in the terminal or yeah it puts it here in the terminal as well and same if i run uh this line so it printed just printed hi and it just tells me yes i i ran that line and it printed here in the terminal right and what i mentioned before this kind of trying to help me if i make a mistake um try and show that so i think in julia you can do print or printal but it shouldn't know what print line is so when i try to run that you can see it turns red and it tells me undefined variable error print line not defined so it's basically trying to tell me this is not correct something's wrong here it's trying to help me figure out where my code is breaking right and then i could if i wanted to i could save this script and i can just kind of quickly simulate that and here you can see sorry if this is a bit small but um you can see that the ending for anything associated with julia files associate associated with julia is dot jl right so here i'm calling it testscript.jl just saving that somewhere and you can see it changed the name up here to testscript.jl name of the file so anything associated with julia is going to have that jl ending right so that's vs code just very quickly just in case you see that but what we want to use is um actually pluto notebooks and i'll show you why so in visual studio code everything that you type in here is going to be interpreted as code and it's trying to run that it's going to try to execute that but in teaching we often want to make comments we often want to say [Music] so i'll just say this is our first code [Music] right so we often want to describe what's happening so we can do that in in a script by using this hashtag to say this line is a comment right this is not going to be run right this is not nothing's happening if i try to run that um because it's just it knows that this is just a comment this should be ignored it's it's going to run the next line instead but if you imagine we're trying to explain a lot uh when we teach this so this is going to be a lot of commented outlines is going to look a bit messy so instead we want to use pluto which is going to look much nicer so i'm going to switch back to the repple to start pluto so you installed it and now in julia so not in the package manager you can just say import oops is important so you can just say import pluto run that doesn't say anything which is fine so now the package is loaded we installed it now we loaded it so you only need to install it once maybe once in a while you need to update it but you only need to install it once generally and and then but every time you use it you need to import it and that's kind of if you know ro python it's kind of a similar idea so we've imported it and now we can say pluto dot run and then just empty brackets so pluto dot run going to run that and that's going to take a second and then it's going to actually open in my browser so this is a browser-based um notebook the recommendation is that you use firefox or chrome for this i think it's just going to open in your standard browser so try that and here we are it's still loading so feel free to try that because it's going to take a couple of seconds the first time you do it um to open and yes i know i have a lot of tabs at some point i might clean them up but probably not okay so here this is kind of the landing page of these pluto pluto notebooks and they offer you a couple of options here so you can open a sample where they've done a couple of things to show what what these notebooks can do you can create a new one or you can open a notebook so here you can either enter a path on your computer or a url so and this is how we plan on distributing kind of teaching material so we'll give you a github file and then you can load it in like this but actually we're going to just create a new notebook for now so click on this and again it's going to take a little bit to do that to open our new notebook and then i'm going to show you how to work with it and the reason why again we've picked um pluto for this so there are also there are other alternatives there's also jupiter um but pluto is all in julia and also has a couple of other cool features one of which i'm going to quickly show you today but essentially the idea here is that we can use a lot of text and a lot of explanations with some code and it's just going to be a lot nicer to read than if we used vs code so that's just why we're choosing that okay it's really taking a while for me let me know if it's loading for you loads for me but i have significantly less tabs okay okay fine yeah you click new notebook and it should um do something so it's a little bit annoying that's kind of the teaching effect right if you want to demonstrate something it's just going to refuse to work but yes you can click create a new notebook and if you're exploring this you can also uh kind of open a sample and see what that looks like it's really weird i tried it earlier and it was fine so i can show it on my screen if you want yeah if you want because it's not really yeah yeah maybe go ahead okay so when i click it i get this um like i said my computer's in default dark mode right now because it's after dark here um yeah so what did you want to show okay so i wanted to show basically that so you have a box here that says enter cell code so let's just add let's just enter a little um little calculation one plus three or something or whatever you want kyla yeah exactly and then we can uh run that there are i think several ways of running that i think you can just do um what is it on is it different on mac is it shift enter or ctrl enter yeah and this is kind of typical the first time you do something in a new notebook or in a new julia script it's going to take a little while and you'll think wait this is this fast new language but it really is just the first the first time you do something with it right so each of these um cells is is a new code block you can only do one line of code so you can only do kind of one we're just doing a little couple of little calculations um if you try to add a line in the same code block it'll complain and it'll actually help you resolve it right so if you do this and then try to run that and so i'm running this by pressing shift enter or you can click this little play button yes that's how it works yeah and and i think the dark mode is just by default kyla right there's a question in the chat but i think that's just your computer yes it's because my computer puts everything in dark mode after a certain time of night to help my eyes i guess yeah yeah and yeah this is maybe something you can set in your browser as well i'm not sure all right so now we have these two lines in the box and it's complaining says multiple expressions in one cell um and it gives you two automatic options to fix this you can either split this up into two different cells um and that's actually what we're going to do so if you click on that kyla it's going to just split it into two cells so it's going to help you kind of um fix that okay um [Music] and what we can also do in this so i kept saying well this is nice because it shows you a lot of text and now we're showing you lots of code so how do you actually get text so you can add a new block you can add a new block here again by clicking on this plus okay and now you can type in md and then quotation marks and then we can just say welcome i don't know welcome to your first pluto notebook all right and if we run that now it'll show up as text and you can show you can see that this is going to all show up above the code block right so all the output so all the calculation results and all this text is going to show up on top of the code block so that's just something that pluto does and you just have to kind of get used to so obviously we don't really want to see this md thing so this is mark down this is similar to how it works in our markdown for example we'll i'll show you a couple of little tricks um to use kind of italics and bold and headline formatting so you can make a really pretty uh document and but of course you don't really want to see this code so you don't want to see this md thing so if you hover over it you'll see this little i symbol and if you click on that the code will disappear right and now you just have this text output and that just makes it look a bit nicer you could also do this with other code so say you have you you're making a graph or something and you only want people to see the graph you're making a report of your research results and you only want people to see the graph or some table or some model output and you don't want them to see the code you can hide any of these code elements by just clicking on this eye and you can hide any of them and then click again to show it again and um you probably caught kyla doing this but you can move these blocks around as you like yeah so there's some text block that we added that makes sense to have it at the top of the screen because it says welcome so we might as well yeah we can just drag and drop to move any cell up and down so if you want to reorder something that works okay so speaking of this markdown stuff if you go to yeah if you go to your text block that you have at the top so this welcome let's make this a headline so we have to show the code again to actually change stuff in it um and if you add a hashtag and a space just one hashtag and a space yeah and then i think you have to run it again to change it you can see that it changed the formatting to make it a big heading right um so then you can hide it again if you want that's actually pretty nice looking so this hashtag and then space um that creates kind of a first level headline we can make a smaller headline by using two hashtags and then an even smaller by using three and so on right so you can do two hashtags smaller headline there you go yeah run it and you can see it's a bit smaller now and then we also what's also really nice is um yeah you can also show this even smaller headlines yeah and what you can also do with this markdown formatting is use bold and italics so let's maybe show that in a new text block um and italics you can either use one asterisk around a word or you can use underscores they should both work i think yeah and then bold is two asterisks yeah so you can see that works that puts the word or you can also do this for several words just puts it in italics and then two asterisks is bold all right so this is just some little formatting uh tricks that you can use um in pluto and then for text you can just always hide your code because it's not really um yeah it's not not all that useful to really show that but if you if you see someone else's notebook and you want to you're wondering oh how did they achieve this cool effect how did they put that formula in or that emoji or whatever you can click on this um crossed out i symbol to see what their code was and how they did it so that's really useful okay um and then one more cool thing maybe you can add a new code block at the end kyla and just write in a equals three so this is a variable that we're creating here um and we'll talk more about variables in some other time but at the moment what this all this means is that whenever julia sees a it's going to replace that with three so let's make a new code block and write a plus one and run that so a plus one and run it and you can see julia added three plus one is four and it gives you four as the output okay um so what pluto does is if you change the value of a variable so can you change can you just write or replace the three with six or something some other number and then run it again so you can see it changed the result in this little calculation we have to seven because it knows even though we didn't run the a plus one line we just ran at the yeah there you go the a equals 500 or a equals six line um but it knows that the assignment has changed so it knows that this value of a has now changed we now want it to be 500 so then it updates it automatically in the entire notebook so this is very useful um yeah and that's one of the reasons why we would like to use it for teaching um yeah and then if you want to if you go back to the top kyla you can save these notebooks um [Music] yeah yeah this will give you a path on your computer and then you can kind of type it in so this is a bit it does work with kind of typing in paths um and you can save it wherever you like and then on this kind of starting page that i showed you um where it says open from file that's where you can open notebooks that you saved or notebooks that you got sent from someone right so you can open um notebooks like that you can save them like that and you can open them like that and i think it has like an auto save feature so it's going to save your work um whenever you add something new um so that you shouldn't really lose any progress all right yes maybe one other thing is how you delete the cell you go over here to this little um three dots so here we have some messy stuff i can go to these three dots and just delete the cell and you can also disable it if you don't want it to be run so if i don't want to be able to run if i don't want this line to be run i can i can disable it here um yeah yeah so i'll put this little notebook in our github even though you can see there's not that much interesting stuff here but just uh for the notes about the um the headers and and that and we're going to be working a lot more with pluto in the future so we're going to get even better acquainted with with pluto and of course with julia um yeah that's and that's about all that we have to show today i think we're coming up on time um it seems like some of some of you may be in time zones where your lunch break is over some of you may be in time zones where you should um go to sleep if you're in india for example um yeah we're really excited that you joined us today and we're really looking forward to continuing to learn julia and to getting into the nitty-gritty um in the future let me see if i can just share this oh okay i close it um so our next one i believe is on march 17th and please do follow us on meetup especially keep an eye out for the coffee meeting on the 27th there's people there of all levels of experience with julia um including people who have a lot of experience with julia but it's a very welcoming and fun group we mostly just talk about what we're using julia for what we might want to use it for anything cool we found so we'd be happy to see you there all right yeah thanks so much for joining we'll stop the