MWE- Minimum Working Example steps guide

Suggest steps to write Minimum Working Example.

When we post an issue here on Discourse. Often helpers want MWE (minimum working example) that reproduces same error or results. For many of us writing a MWE is usually tough.

  • DATA- Often our code is using some data. Data can be constant, ascending, descending or random and can be created using Single- and multi-dimensional Arrays · The Julia Language

    • Constant data
    fill(9,(2))     # to create 1d data with 9 at two places
    fill(5,(2,3))      # to create 2d matrix having 5 everywhere
    fill(8,(2,3,5))
    fill("text",(2,3))     # text can also be created
    
    • Ascending data
    range(start=23, stop=209, length=20)     # data will 20 values  starting from 23 and go up to 209
    range(start=23, stop=209, step=5)     # [23, 28, 33, 38, ...] data will start from 23 adding 5 each time and can go up to 209
    
    • Descending data
    range(start=23, stop=-209, length=20)    # It will output 20 values between 23 and -209
    range(start=23, stop=-209, step=-5)    # [23, 18, 13, 8, ....-207]
    
    • Random data
    rand(Int, 7)
    rand(Float32, (2, 3))       # create 2x3 matrix of random Float32
    rand(Float16, (3,5,2))       # create 3x5x2 matrix of random Float16
    

PS: You can copy good content/suggestions of other’s post in your post and i will mark best post as solution.

1 Like
  1. Code should be fixed: re-running this code multiple times should use the exact same data and produce exactly the same results. If the point is to demonstrate that code which should be deterministic behaves randomly, run the offending code multiple times in a loop. Fixed code means:
    • Fixed random number generators. If you’re calling rand anywhere in your code, make sure not to use the global random number generator. Pass a random number generator with a fixed seed to all functions that accept a random number generator.
    • Fixed data. If your code depends on data, try to remove this dependency first by reproducing the problem with random data (see previous point). If this doesn’t work, try to reproduce the problem with the minimum amount of data and include the data in your post verbatim.
    • Fixed package versions. Ideally, code should begin with import Pkg; Pkg.activate(temp=true); Pkg.add(packages with specified versions). Or list relevant package versions in the post.
  2. Code should be small. Don’t post hundreds of lines of code. Isolate the problem and post this.
  3. Code should be readable. This isn’t code golf: code should be small and readable. If people struggle to parse your code, they’ll be less likely to help. Use meaningful variable and function names, write comments.
  4. Code should be self-contained. People shouldn’t have to download 3rd-party binaries or request missing code in order to run your MWE. The MWE should be the only piece of code (apart from packages it uses) needed to reproduce the problem.
  5. Code should reproduce the issue. Before posting, run your code several times in a fresh Julia session. This can be done by running julia yourcode.jl from the terminal. Do you get the problematic behavior every time? If not, see point (1) of this list.

More explanation can be found on Stack Overflow: https://stackoverflow.com/help/minimal-reproducible-example.

2 Likes