jarno
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: Worshop --- # Introduction to Julia This document: https://hackmd.io/@jarno/S1g_QtAkK/edit Zoom room: 613 3982 7511 (no password) Zoom link: https://aalto.zoom.us/j/61339827511 Materials: https://github.com/AaltoRSE/julia-introduction#cloning-the-materials Code of conduct: https://www.aalto.fi/en/aalto-university/code-of-conduct-values-into-practice Garage: https://scicomp.aalto.fi/help/garage/ Seminar on Julia Packaging: https://nordic-rse.org/events/seminar-series/ ## Schedule ### Tuesday This schedule is tentative. | Time | Duration | Session | ---- | -------- | ------- | 09:00 | 60min | Intro to Julia | 10:00 | 10min | Coffee break | 10:10 | 50min | Functions | 11:00 | 10min | Coffee break | 11:10 | 50min | Control flow | 12:00 | 10min | Coffee break | 12:10 | 50min | IO | 13:00 | | End of day ### Wednesday | Time | Duration | Session | ---- | -------- | ------- | 09:00 | 60min | Plotting and Using Packages | 10:00 | 10min | Coffee break | 10:10 | 50min | Types and Multiple Dispatch | 11:00 | 10min | Coffee break | 11:10 | 50min | Development Practices | 12:00 | 10min | Coffee break | 12:10 | 50min | Performance Tips | 13:00 | | End of day --------- ## Icebreaker questions: - What programming languages do you know? - Matlab: 7 - Python: 13 - IDL: 1 - FORTRAN: 2 - C: 7 - C++: 5 - Swift: 1 - Objective-C: 1 - BASIC: 1 - R: 6 - JavaScript: 2 - LISP (Scheme, CLOS, Clojure): 1 - Java: 3 - Shell: 5 - Scala: 1 - Tcl: 1 - ... - Have you used Julia in a project? - No: 13 - ... - ... - What would you like to learn on this course? - Whether or not I should invest effort into learning Julia. +1 +1 - What the benefits of using Julia are? +1 - How difficult it would be to switch to Julia? - Tips on porting stuff from C or Python +1 +1 - Is parallel programming possible with Julia? +1 - Does Julia work with GPUs? +1 +1 - ... - ... - ... - Do you know any programming language? - Yes: oooooooooooooo - No: --------- ### Things I love about Julia already * Native support for fractions: `1//3` * Multiplication without `*`: `2x` --------- # Questions for day 1 - As questions like this - And answer like this - To reply to an answer, indent a bit more - git URL: `git clone https://github.com/AaltoRSE/julia-introduction.git` - I guess if you are using jupyter.cs.aalto.fi this is not needed, is the interface already there? - Yes - How do you get out of the shell? - I guess this is in REPL. backspace does it, or running any command. - How to type in a emoji? - `\` starts a completion of unicode names, so you can `\alpha`TAB - How are fractions stored internally? - Is it an int/int representation in the background or something more complicated? - `typeof(3//2)` shows me `Rational{Int64}` which may give some clues to storage - That's what is lost on me... 1//3? - I interpert this as "a new data type that stores the numerator and denominator separately as Int64" as a specialized type. Just a guess though. - Two Int64 ints or just one somehow split in two? (asking from a memory allocation point of view) - Got it. sizeof(1) -> 8. sizeof(1//3) -> 16. Cheers! +1 - With so many pre-defined functions, isn't the namespace crowded (and we risk overwriting pre-defined stuff)? - I guess that the functions in a package you write yourself should always go on some namespace? - `cell::Int8 = 1` but `cells = Int8[1 1]`. Is there a good reason for this. - You can also use 'cell = Int8(1)' and 'cells::Array{Int8, 2} = [1 1]' - Thanks! syntactic sugar it seems. Useful. - is `broadcast` like broadcasting in numpy, increasing array dimensionality when needed? - Broadcast can do multiple things, depending what the inputs are. The following will use the dimension that matches ```julia a = [1,2] b = [1 2 3; 4 5 6] a .+ b ``` - yes! So like numpy. do you find it hard to keep the different axes clear in your mind (I always have this issue with numpy, for complex stuff) - Yes, definitely. - You can also specify the index, but if it get's that complex I recommend using a for loop in a function. In Julia, loops are not slow. - What is the difference in `[1 2]` syntax and `[1, 2]`? (comma) Looks like dimensionality of final result...? - space syntax makes an matrix instead of an array - I did `function addone(value_to_add,obj) result=obj.+value_to_add end addone(3,[1,2])` And now I would like to use the map function with the array. `A=zeros(5,5) map(addone,A)` But it's strange. Should the map function not allow me still an input parameter for the addone function? - ~~Map only accepts a function with 1 parameter (I think)~~ - Okay. No, my addone function has two input arguments. The value to add and the object the value is added to. - You can use multiple arguments: `map(add_one, [1,2,3], 2)` - Solved, thanks. - was trying broadcast with my 2-argument version of poly2, and it silently works even with a missing argument. I can also run poly2 with only one argument, and it works. What happens to missing arguments? - Do you still have the one-argument version defined? Julia allows overloading. - yes! that's it, it finds the old one. When I try with no arguments it makes this clear: ``` poly2() MethodError: no method matching poly2() Closest candidates are: poly2(!Matched::Any) at In[5]:1 poly2(!Matched::Any, !Matched::Any) at In[16]:1 ``` - To list defined method use `methods(function_name)` - Should one write in a Julia function `return variable` to return something out of a function, please? - You can use `return variable`, but if you don't, the function will return the result of the last statement. So this returns 3: ```julia function return_three() 1+2 end ``` - How do you get the inequality sign, please? - `\ne`TAB - Should the 'include("../../epidemic_simple.jl")' in fact be 'include("../epidemic_simple.jl")', or did I somehow mess up the directory structure? - Yes, it should! - is there a difference between "array" and "list", or is there only "array"? - ? - (Answered this below. sorry.) Julia has `Vector`, `Matrix` and `Array`. `Vector` is always 1D, `Matrix` is always 2D and `Array` can have any dimension. - (continued from above) and is resizing a low-complexity operation? e.g. in Python I think that numpy arrays are copied if resized, while lists are designed for in-place extension. (and I think this comes from the way `realloc` works, expanding continuous memory may return a new pointer so increasing size = possible copy. and `list` has more overhead but designed for for expanding) - Not an expert, but I believe arrays are always contiguous in memory, so resizing requires copying. - Vectors in Julia seem to be similar to Python lists (i.e. dynamic arrays). - is there a difference between "2-dimensional array" and "matrix"? - Julia has `Vector`, `Matrix` and `Array`. `Vector` is always 1D, `Matrix` is always 2D and `Array` can have any dimension. - A 2D Array may be implemented differently than Matrix. There could be performance differences, but the syntax is very similar. - `using` to load packages - are things always put in one namespace? (I guess one can make own namespace in package though?) - why would I use a raw string instead of simply escaping the $, please? - If the string contains a lot of characters that need to be escaped, it is much more readable as a raw string. - are specialized strings generic, so that they can be arbitrarily defined by libraries? - I cannot find a way of defining a custom specialized string. You can always define a struct that contains a string, but it has a different syntax. ----------- # Feedback for day 1 Add "o" if you agree: - We did not have enough exercises: o - Needed more time for exercises: ooo - Exercises were too easy: - these exercises were nice to begin with, but I would have liked additional exercises with increasing complexity +1 +1 - Exercises were too hard: Write something positive here: - Julia seems very expressive, and the basics were nicely covered. The exercises were simple but useful. - It was nice of you to remind to use the breaks for getting up instead of sitting at the computer. It's something that is forgotten all too easily. +1 +1 - Nice exposition of language features and where it gets really powerful (e.g broadcasting functions) - Very clear progression of material. It is a joy to grasp nearly everything on the first go. - Nice introduction, covered the basics: this is what I expected from the course so far - Yes, Julia seems to be a better version of Matlab. Lots of things reminded me of Matlab. Write something constructive here: - How about a Q&A session in-between on the exercises? It was a bit one-direction only. +1 - ... - Would like to know more about back-end handling of data etc. - I follow your screen presentation all the time. I am confused when you mention exercises. Were we supposed to work on exercises besides your explanations? - Sorry for the confusion. Time for exercises was separate from the presentaion and always before a break (this is probably the source of the confusion.) - I cloned the github repo and follwed the standard exercises, not the pandemic one. When was I supposed to work on this one, please? - Some of the exercises (but not many) are related to the pandemic model. There are more tomorrow - There is one exercise in control flows and one in IO about the pandemic model - I find it hard to follow what you are showing and typing at the same time, my screen is not big enough to display many windows (I tried to minimize zoom and have another window with the jupyter but that was not optimal and I missed what was going on in the HackMD): is there a "good" way to do that? - It is still not clear to me what are the advantages of Julia over Python. +2 - Can't really say yet. We still have another day. :) --------------------------- # Day 2 ### Package development in Julia Seminar Speaker: Luca Ferranti, University of Vaasa, Finland. 18.08.2021 at 14:00-17:00 EEST Check https://nordic-rse.org/events/seminar-series/ for details. ### Comments on day 1 questions - Luca Ferranti answered the question about resizing arrays. Arrays are contiguous in memory, but Julia allocates them in a smart way, so that it does not always cause a copy. - Full technical conversation at https://coderefinery.zulipchat.com/#narrow/stream/119815-general/topic/Julia.20question ### How is Julia different from Python: - Functions are compiled are therefore fast - Multiple dispatch (will cover today) - No classes (replaced by multiple dispatch) ### How is Julia different from C, C++ and Fortran? - Dynamic typing and duck typing - Built-in package manager - JIT compilation - Functions are compile units - Multiple dispatch (will cover today) ----------------- ## Questions about day 2: - This is a question or a comment. - This is an answer - How `rand` and palette (as defined using `colors`) interact is defined in `colors`. Is this correct? - I am not sure I understand your question. Do you refer to something Jarno showed? - If you check ?rand, you will see that one of the options for the first argument is an indexable collection (e.g. a palette). - Got that. I thought it was more complicated: that the called ~~object~~ decides how to react to the call. As Jarno said, it takes some time to think in the stateless/functional programming mode. - Do all of the Julia plotting things rely on other languages? (not saying this is bad, it's actually nice) - I don't think plotly does - Plotly is JavaScript, isn't 0000000000000000000000000000000000000000000000000000000000it? - There is a separate plotlyjs package. Not sure what the difference is. - Plotly seems to add interaction to PlotlyJS. It users PlotlyJS under the hood. - Regarding the ! notation for functions that mutate passed values: is this purely convention or can Julia enforce it? - It is purely a convention and has no syntax behind it - :+1: - Interesting: https://discourse.julialang.org/t/why-is-enum-0-based/12722/6 :::info Exercise 8 untill 12:30 ::: ## What to do in the last session (poll) Vote by adding an 'o' at the end - Like this: o - Exercises: - Nicer functions: - Compilation: - Parallel computing: oooo - Vectorization: - Metaprogramming: - Performance tips: - May I suggest something else here (interoperability with other languages)? - I cannot cover much more than I have said. Don't really have experience here. - Ok - See section 10 for PyCall and Ccall, but I already showed these. There are also links to documentation. - Is there something about calling compiled Julia code in other languages? - From which language? Calling from C or Fortran is not complicated, but requires compiling the functions first. Calling from Python is possible with the "julia" package. - C calling interface works pretty much everywhere, so that will suffice, but if there is a direct way of calling from Python, that is interesting as well, for sure. - Use the "julia" package in Python. But you need to use the python-jl interpreter instead of the standard one (or compile a statically linked interpreter). - See https://pypi.org/project/julia/ # Feedback from Day 2 Write Something positive here: - Very interesting topics, especially those about threads and MPI, a pity we did not have time to spend more time with these (I guess that is what I will be doing in the exercises) - I think a good course should have more material than can be covered, so that we can adjust based on what you are interested in. Feel free to go through the rest of the materials and ask questions. - For asking questions, see scicomp.zulip.cs.aalto.fi (only for Aalto people) and coderefinery.zulipchat.com. - Clear explanations and good examples - A nice intro, enough to get interested to try more things and start projects +1 +1 +1 +1 - Really nice that we kind of did our first Julia project (epidemic simulation) while going through the exercises. - It was good to get an overview of what is feasible with Julia, and seeing you do it and type along was instructive, however I have the feeling that we only scratched the surface and would need to spend more time on a similar course, now that I know better what to expect: is there a plan to organise that, over several more days (this structure with sessions in the morning and free afternoon was perfect for me)? - The coverage and choice of topics on both the days was excellent (keeping in mind the comment below). I feel ready to dive into topics that tickled my interest. +1 - Courses like this are really good for getting started with a new language or technology. You could always go through some materials alone, but dedicating a day or two to go through some basics doesn't necessarily happen without a course like this, and if someone has thought of a good structure to do that – like now – it makes it much more effective. +111 - this format is kinda perfect for introductory courses to any programming language that could be organised every year before the beginning of first semester in university - ... - ... - ... - ... Write something constructive ("negative") here: - For me there was too much material covered too quickly on the second day. +1 +1 - Quite "dense" day, with many topics, could have been easily split in 2 sessions (that is 3x half days in total) - Overall, I think that the course can be split for two audiences: - An Intro to Programming course: covering how to code and programming contructs using the slow pace of yesterday (you don't expect a beginner to be using threads and other similarly advanced features that were discussed today) - Then a How to use Julia course for those who already know programming in other languages so that they can switch to Julia if they deem fit. This would be more comparative and discuss topics that were covered today. - I do not necessarily agree: if as a beginer you have never heard about the advanced features offered by Julia you may never be tempted to look into these, so I think that getting a broad overview even when you start is good, and this is what this course did. Of course to get deeped into Julia more courses would be welcome, at various levels. - Parameters struct is different in the notebook 07 vs epidemic_no_immunity.jl used in exercises. Caused a little bit of confusion at first. +1 - I would appreciate "real" breaks, I mean NOT mixed with exercises, and longer exercise sessions to have time to think about the problems and not simply go to the solutions because I have not enough time and the main course resumes +1 - Today's exercises were more time consuming and having a bit longer exercise sessions would help +1 - The epidemic exercises could perhaps be continued in the threading section - Maybe some quizzes using mentimeter would be nice to increase our participation. - I am under the impression that the attendance was a little overwhelmed after the first hour or so, and a more active participation with a bit more interactivity could have been better - The last session (parallel computing) was clearly an add-on, not a well thought of module like the rest of the sessions. The MPI exercise is really basic, and all the code was given, whereas the language features for parallel computing were shown very hastily, so I didn't really catch all while it was presented. I can go through some documents on my own, but since it didn't come up during the two days I had dedicated for this, it may take a while before it happens. I think it's ok to choose a focus and stick to it instead of trying to cater for everyone at the last moment. (It was nice that you polled our interests before the course, though.) - ... - ... - ... - ...

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully