Skip to content

Instantly share code, notes, and snippets.

@vtjeng
Last active May 25, 2020 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtjeng/ce1150cc50515c9e35d9e349ded8c409 to your computer and use it in GitHub Desktop.
Save vtjeng/ce1150cc50515c9e35d9e349ded8c409 to your computer and use it in GitHub Desktop.
Guide to local development for the MIPVerify Julia Package

This is a guide for local development of a Julia package in Julia 1.0 and above.

tl;dr: We use a new environment to ensure that our regular Julia environment is not affected.

Setting up a new environment

Navigate to ~/.julia/environments. This folder should contain the default environment. (I am currently working in Julia 1.0, so the environments folder contains the folder v1.0).

From the same folder, make a new project by running julia, then entering the Pkg repl by pressing ] from julia.

Upon entering the Pkg REPL, you should see a prompt like this:

(v1.0) pkg>

We set up a new active environment for development. To set the active environment, use activate:

(v1.0) pkg> activate v1.0-MIPVerify
[ Info: activating new environment at ~/.julia/environments/v1.0-MIPVerify/

I've chosen the environment name v1.0-MIPVerify as a convention to remind me what package I'm editing.

Now, we use develop to set up a git clone of the MIPVerify package.

(tutorial) pkg> develop --local MIPVerify
...

(v1.0-MIPVerify) pkg> status
    Status `~/.julia/environments/v1.0-MIPVerify/Project.toml`
  [e5e5f8be] MIPVerify v0.2.0 [`dev/MIPVerify`]

Running tests

Running all tests as in CI

To run the full suite of tests as it would be done on CI, run

$ (cd ~/.julia/environments && julia -e 'using Pkg; Pkg.activate("v1.0-MIPVerify"); Pkg.test("MIPVerify")')

...

 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                               Time                   Allocations      
                                                                                       ──────────────────────   ───────────────────────
                                   Tot / % measured:                                         311s / 99.1%           17.8GiB / 98.9%    

 Section                                                                       ncalls     time   %tot     avg     alloc   %tot      avg
 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 integration/                                                                       1    98.1s  31.9%   98.1s   3.47GiB  19.7%  3.47GiB
   sequential/                                                                      1    98.1s  31.8%   98.1s   3.47GiB  19.7%  3.47GiB
     generated_weights/                                                             1    98.1s  31.8%   98.1s   3.47GiB  19.7%  3.47GiB
       conv+fc+softmax.jl                                                           1    69.6s  22.6%   69.6s    879MiB  4.88%   879MiB
         BlurringPerturbationFamily                                                 1    38.8s  12.6%   38.8s    696MiB  3.87%   696MiB
         UnrestrictedPerturbationFamily                                             1    29.5s  9.57%   29.5s    152MiB  0.85%   152MiB
           Minimizing lInf norm                                                     1    10.5s  3.41%   10.5s   14.2MiB  0.08%  14.2MiB
           With multiple target labels specified, minimum target label found        1    7.65s  2.48%   7.65s   46.0MiB  0.26%  46.0MiB
           Minimizing l1 norm                                                       1    5.88s  1.91%   5.88s   57.2MiB  0.32%  57.2MiB
           Increasing margin increases required distance                            1    5.45s  1.77%   5.45s   35.0MiB  0.19%  35.0MiB
         LInfNormBoundedPerturbationFamily                                          1    1.24s  0.40%   1.24s   22.9MiB  0.13%  22.9MiB
       mfc+mfc+softmax.jl                                                           1    28.1s  9.12%   28.1s   2.61GiB  14.9%  2.61GiB
 utils/                                                                             1    96.9s  31.5%   96.9s   6.47GiB  36.8%  6.47GiB
   import_example_nets.jl                                                           1    88.1s  28.6%   88.1s   3.20GiB  18.2%  3.20GiB
     get_example_network_params                                                     1    88.1s  28.6%   88.1s   3.20GiB  18.2%  3.20GiB
       MNIST.WK17a_linf0.1_authors                                                  1    80.8s  26.2%   80.8s   1.58GiB  8.96%  1.58GiB
       MNIST.RSL18a_linf0.1_authors                                                 1    5.22s  1.69%   5.22s    833MiB  4.63%   833MiB
       MNIST.n1                                                                     1    2.18s  0.71%   2.18s    835MiB  4.64%   835MiB
   import_datasets.jl                                                               1    8.16s  2.65%   8.16s   3.26GiB  18.6%  3.26GiB
 batch_processing_helpers/                                                          1    84.1s  27.3%   84.1s   6.54GiB  37.2%  6.54GiB
   integration.jl                                                                   1    79.6s  25.8%   79.6s   5.74GiB  32.6%  5.74GiB
   unit.jl                                                                          1    3.98s  1.29%   3.98s    818MiB  4.55%   818MiB
 net_components/                                                                    1    28.9s  9.38%   28.9s   1.10GiB  6.27%  1.10GiB
   layers/                                                                          1    8.96s  2.91%   8.96s    616MiB  3.42%   616MiB
   core_ops.jl                                                                      1    7.49s  2.43%   7.49s    349MiB  1.94%   349MiB
   nets/                                                                            1    124ms  0.04%   124ms   6.97MiB  0.04%  6.97MiB
 models.jl                                                                          1   11.2ms  0.00%  11.2ms    167KiB  0.00%   167KiB
 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Test Summary: | Pass  Total
MIPVerify     |  268    268
   Testing MIPVerify tests passed 

Note that a paranthesized command is run in a subshell; we are inspired by this trick.

Running additional tests (Gurobi only)

If you have Gurobi installed locally, and would like to run more tests (some tests are skipped when only Cbc is available), you can also run

$ (cd ~/.julia/environments && julia -e 'using Pkg; Pkg.activate("v1.0-MIPVerify"); include("v1.0-MIPVerify/dev/MIPVerify/test/runtests.jl")')

...

 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                               Time                   Allocations      
                                                                                       ──────────────────────   ───────────────────────
                                   Tot / % measured:                                         292s / 98.8%           21.7GiB / 99.0%    

 Section                                                                       ncalls     time   %tot     avg     alloc   %tot      avg
 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 integration/                                                                       1     142s  49.2%    142s   9.02GiB  41.9%  9.02GiB
   sequential/                                                                      1     142s  49.2%    142s   9.02GiB  41.9%  9.02GiB
     trained_weights/                                                               1    83.5s  29.0%   83.5s   5.46GiB  25.4%  5.46GiB
     generated_weights/                                                             1    58.1s  20.2%   58.1s   3.56GiB  16.6%  3.56GiB
       mfc+mfc+softmax.jl                                                           1    39.9s  13.8%   39.9s   2.76GiB  12.8%  2.76GiB
       conv+fc+softmax.jl                                                           1    17.8s  6.19%   17.8s    822MiB  3.73%   822MiB
         BlurringPerturbationFamily                                                 1    10.8s  3.76%   10.8s    659MiB  2.99%   659MiB
         UnrestrictedPerturbationFamily                                             1    6.67s  2.31%   6.67s    142MiB  0.65%   142MiB
           Increasing margin increases required distance                            1    2.45s  0.85%   2.45s   35.0MiB  0.16%  35.0MiB
           Minimizing l1 norm                                                       1    2.34s  0.81%   2.34s   47.7MiB  0.22%  47.7MiB
           Minimizing lInf norm                                                     1    1.21s  0.42%   1.21s   14.3MiB  0.06%  14.3MiB
           With multiple target labels specified, minimum target label found        1    668ms  0.23%   668ms   45.5MiB  0.21%  45.5MiB
         LInfNormBoundedPerturbationFamily                                          1    219ms  0.08%   219ms   13.2MiB  0.06%  13.2MiB
 utils/                                                                             1    96.5s  33.5%   96.5s   6.08GiB  28.2%  6.08GiB
   import_example_nets.jl                                                           1    91.7s  31.9%   91.7s   3.08GiB  14.3%  3.08GiB
     get_example_network_params                                                     1    91.7s  31.9%   91.7s   3.08GiB  14.3%  3.08GiB
       MNIST.WK17a_linf0.1_authors                                                  1    84.6s  29.4%   84.6s   1.55GiB  7.19%  1.55GiB
       MNIST.RSL18a_linf0.1_authors                                                 1    5.95s  2.07%   5.95s    830MiB  3.77%   830MiB
       MNIST.n1                                                                     1    1.20s  0.42%   1.20s    741MiB  3.36%   741MiB
   import_datasets.jl                                                               1    4.20s  1.46%   4.20s   3.00GiB  13.9%  3.00GiB
 batch_processing_helpers/                                                          1    26.9s  9.35%   26.9s   5.35GiB  24.9%  5.35GiB
   integration.jl                                                                   1    22.6s  7.84%   22.6s   4.57GiB  21.2%  4.57GiB
   unit.jl                                                                          1    3.87s  1.34%   3.87s    801MiB  3.63%   801MiB
 net_components/                                                                    1    22.7s  7.90%   22.7s   1.06GiB  4.93%  1.06GiB
   layers/                                                                          1    7.85s  2.73%   7.85s    579MiB  2.63%   579MiB
   core_ops.jl                                                                      1    3.89s  1.35%   3.89s    345MiB  1.57%   345MiB
   nets/                                                                            1    130ms  0.05%   130ms   6.96MiB  0.03%  6.96MiB
 models.jl                                                                          1   11.1ms  0.00%  11.1ms    167KiB  0.00%   167KiB
 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Test Summary: | Pass  Total
MIPVerify     |  279    279

Running a subset of tests

We've also organized the tests so you can run the subset contained in a particular file:

$ (cd ~/.julia/environments && julia -e 'using Pkg; Pkg.activate("v1.0-MIPVerify"); include("v1.0-MIPVerify/dev/MIPVerify/test/net_components/layers/conv2d.jl")')
Academic license - for non-commercial use only
Academic license - for non-commercial use only
Test Summary: | Pass  Total
conv2d.jl     |   22     22

Note that you will not get the useful end-of-test summary on runtime for each test component when you run a file other than runtests.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment