Julia Utilities for The Conic Benchmark Format

ConicBenchmarkUtilities

Utitilies to convert between CBF and MathProgBase conic format.

How to read and solve a CBF instance:

dat = readcbfdata("/path/to/instance.cbf") # .cbf.gz extension also accepted

# In MathProgBase format:
c, A, b, con_cones, var_cones, vartypes, sense, objoffset = cbftompb(dat)
# Note: The sense in MathProgBase form is always minimization, and the objective offset is zero.
# If sense == :Max, you should flip the sign of c before handing off to a solver.

# Given the data in MathProgBase format, you can solve it using any corresponding solver which supports the cones present in the problem.
# To use ECOS, for example,
using ECOS
solver = ECOSSolver()
# Now load and solve
m = MathProgBase.ConicModel(ECOSSolver(verbose=0))
MathProgBase.loadproblem!(m, c, A, b, con_cones, var_cones)
# Continuous solvers need not implement setvartype!
if !all(vartypes .== :Cont)
    MathProgBase.setvartype!(m, vartypes)
end
MathProgBase.optimize!(m)
# Solution accessible through:
x_sol = MathProgBase.getsolution(m)
objval = MathProgBase.getobjval(m)
# If PSD vars are present, you can use the following utility to extract the solution in CBF form:
scalar_solution, psdvar_solution = ConicBenchmarkUtilities.mpb_sol_to_cbf(dat,x_sol)

How to write a CBF instance:

newdat = mpbtocbf("example", c, A, b, con_cones, var_cones, vartypes, sense)
writecbfdata("example.cbf",newdat,"# Comment for the CBF header")

Note that because MathProgBase conic format is more general than CBF in specifying the mapping between variables and cones, the order of the variables in the CBF file may not match the original order. No reordering takes place if var_cones is trivial, i.e., [(:Free,1:N)] where N is the total number of variables.

How to write a JuMP model to CBF form:

m = JuMP.Model()
@variable(m, x[1:2])
@variable(m, t)
@constraint(m, norm(x) <= t)
ConicBenchmarkUtilities.jump_to_cbf(m, "soctest", "soctest.cbf")

Download Details:

Author: JuliaOpt
Source Code: https://github.com/JuliaOpt/ConicBenchmarkUtilities.jl 
License: View license

#julia #utilities 

What is GEEK

Buddha Community

Julia Utilities for The Conic Benchmark Format

Julia Utilities for The Conic Benchmark Format

ConicBenchmarkUtilities

Utitilies to convert between CBF and MathProgBase conic format.

How to read and solve a CBF instance:

dat = readcbfdata("/path/to/instance.cbf") # .cbf.gz extension also accepted

# In MathProgBase format:
c, A, b, con_cones, var_cones, vartypes, sense, objoffset = cbftompb(dat)
# Note: The sense in MathProgBase form is always minimization, and the objective offset is zero.
# If sense == :Max, you should flip the sign of c before handing off to a solver.

# Given the data in MathProgBase format, you can solve it using any corresponding solver which supports the cones present in the problem.
# To use ECOS, for example,
using ECOS
solver = ECOSSolver()
# Now load and solve
m = MathProgBase.ConicModel(ECOSSolver(verbose=0))
MathProgBase.loadproblem!(m, c, A, b, con_cones, var_cones)
# Continuous solvers need not implement setvartype!
if !all(vartypes .== :Cont)
    MathProgBase.setvartype!(m, vartypes)
end
MathProgBase.optimize!(m)
# Solution accessible through:
x_sol = MathProgBase.getsolution(m)
objval = MathProgBase.getobjval(m)
# If PSD vars are present, you can use the following utility to extract the solution in CBF form:
scalar_solution, psdvar_solution = ConicBenchmarkUtilities.mpb_sol_to_cbf(dat,x_sol)

How to write a CBF instance:

newdat = mpbtocbf("example", c, A, b, con_cones, var_cones, vartypes, sense)
writecbfdata("example.cbf",newdat,"# Comment for the CBF header")

Note that because MathProgBase conic format is more general than CBF in specifying the mapping between variables and cones, the order of the variables in the CBF file may not match the original order. No reordering takes place if var_cones is trivial, i.e., [(:Free,1:N)] where N is the total number of variables.

How to write a JuMP model to CBF form:

m = JuMP.Model()
@variable(m, x[1:2])
@variable(m, t)
@constraint(m, norm(x) <= t)
ConicBenchmarkUtilities.jump_to_cbf(m, "soctest", "soctest.cbf")

Download Details:

Author: JuliaOpt
Source Code: https://github.com/JuliaOpt/ConicBenchmarkUtilities.jl 
License: View license

#julia #utilities 

How to Utilize Java Benchmarks With Arm Processors

I have seen a lot of speculation surrounding ARM processors, specifically after Apple announced its plan to change over to Arm-based processors. Many people assume that the performance will be similar to a Raspberry Pi, however, this is incorrect. While Java on ARM is not uncommon, there has been a recent spike due to increased ARM investments from cloUd vendors. Amazon and Microsoft have taken steps towards this, with Amazon updating its ARM offerings, and Microsoft porting the JVM to Arm64 for Windows, which will be helpful for future Azure support.

In this article, I will show the Java benchmarks I took on different AWS EC2 instances, and for fun on my laptop.

  1. Amazon a1.large (ARMv8 Cortex-A72, 2 Cores, 4GB RAM).
  2. Amazon m6g.medium (ARMv8 Neoverse-N1, 1 Core, 4GB RAM).
  3. Amazon t3.medium (Intel Xeon Platinum 8259CL, 1 Core / 2 Threads, 4GB RAM).
  4. Apple MacBook Pro (Intel i9 2.4GHz, 8 Core / 16 Threads, 64GB RAM).

The Arm trademark will be referred to as such. Although it was previously written “ARM”, it is now “Arm”.

#java #aws #arm #benchmark #how to utilize java benchmarks with arm processors #utilize java benchmarks

How Benchmarking Your Code Will Improve Your Ruby Skills

Learning to code is a path full of struggles, and learning Ruby isn’t the exception. But you’ll agree with me, that practice is the best way to learn and develop your skills.

Out there are plenty of sites to choose from where you can achieve this. But after n amount of solved challenges, you’ll start questioning your solutions.

You’ll start feeling, that is not enough to come up with an answer to the challenge. And you’ll be wondering if there is a better, faster, and less consuming memory approach.

If this is your case, if you have reached this stage, then you’re more than ready to begin benchmarking your code. And if you’re not, well, let me tell you that learning this will step up your game.

So, what is this “benchmarking” thing anyway?..

Benchmarking is the process of measuring the performance of something… in this case the performance of your code.

Benchmarking is the process of measuring the performance of something.

And that’s it, there is nothing more to add.

Yeah, I know what you’re thinking, that knowing the meaning doesn’t serve your purpose. But I’m positive that at least it will give you a broad idea.

With this in mind, the next question to answer is, “How benchmarking my code, will help me improve my coding skills?”.

This is an easy one. Benchmarking gives you knowledge, and knowledge is power. The better understanding of your code, the better code you’ll start programming. Is that simple!.

Benchmarking gives you knowledge, and knowledge is power.

Benchmarking gives you a simple view of how your code is performing. This view focuses on three main areas: elapsed timememory, and iterations per second.

  1. Elapsed time: is the amount of time your code takes to finish a task.
  2. Memory: is the allocated space in your drive that your code occupies to solve the task.
  3. Iterations per second: is the total number of repetitions your code can do the same task, over and over, in a second.

Ok, at this point I assume you have understood the basics of benchmarking. Hopefully, you are also saying to yourself - “Yeah, this is what I was missing, this will help me become a better programmer!”.

If you don’t think that way yet; I hope knowing how it works will do.

Now, how do we apply this?

Ruby makes it easy for us, as it already has a “Benchmarking” class, but we’ll complement it with two other ruby gems.

  1. Benchmarking-ips
  2. Benchmarking-memory

Before describing the steps to benchmark your code. I’m assuming you are using a linux/unix distribution, and have a working version of Ruby installed.

If you’re running some other OS like Windows, the next series of commands, probably, won’t work. But the benchmarking steps are going to be identical.

Let’s begin!.

a. The first step is to install this rubygems in your system; for that, you can use this command:

gem install benchmark-ips benchmark-memory

b. The second **step **is creating a ruby file, I’m going to call it “benchmarking_ruby.rb”, but you can name it in any way you want:

touch benchmarking_ruby.rb

b.1 Open the file with your preferred text editor. This file will contain three main sections:

- Section 1: Here we use require to include and grant our file access to the gems recently installed and the Ruby Benchmark Class. Doing so, will allow us to use the benchmark methods to measure our code performance.

require 'benchmark'
require 'benchmark/memory'
require 'benchmark/ips'

Section 2: We write the code that we want to benchmark.

def method_1(params)
    ## some code
end

def method_2(params)
    ## some code
end

Note:_ Benchmark works if you want to measure a single method but it’s best if you test at least two or more. Don’t worry too much about this right now, later on, I’ll show you an example and you’ll understand what I meant._

- Section 3: We set up the test.

This part is tricky but not complicated. Look at the image below and try to identify what’s happening.

def benchmark(params)
    Benchmark.bmbm do |x|
        x.report ("Method One") { method_1(params) }
        x.report ("Method Two") { method_2(params) }
    end

    Benchmark.memory do |x|
        x.report ("Method One") { method_1(params) }
        x.report ("Method Two") { method_2(params) }
        x.compare!
    end

    Benchmark.ips do |x|
        x.report ("Method One") { method_1(params) }
        x.report ("Method Two") { method_2(params) }
        x.compare!
    end
end

benchmark(params)

We are declaring a method called “benchmark” that accepts some parameters (or arguments).

def benchmark(params)
    ...
end

#ruby #benchmark #learn-to-code-ruby #rubygems #code-performance #how-to-benchmark-ruby #benchmark-ips #benchmark-memory

Monty  Boehm

Monty Boehm

1660108740

FastaIO.jl: Utilities to Read/write FASTA format Files in Julia

FastaIO.jl

Utilities to read/write FASTA format files in Julia.

Installation and usage

Installation

To install the module, use Julia's package manager: start pkg mode by pressing ] and then enter:

(v1.3) pkg> add FastaIO

Dependencies will be installed automatically. The module can then be loaded like any other Julia module:

julia> using FastaIO

Documentation

  • STABLEmost recently tagged version of the documentation.
  • DEVin-development version of the documentation.

See also the examples in the examples/ directory.

Download Details:

Author: Carlobaldassi
Source Code: https://github.com/carlobaldassi/FastaIO.jl 
License: View license

#julia #format #files 

Monty  Boehm

Monty Boehm

1659604260

A Julia-Erlang Module for using The External Term Format From Julia

ErlPort

A Julia-Erlang module for using the External Term Format from Julia

Though this module can be used stand-alone, it was originally designed to be used with the ErlPort project, allowing Julia code to be run from Erlang and LFE, sending its results back as Erlang terms.

Prerequisites

  • ErlPort.jl works with Julia 1.0.

Installation

The following example shows installing ErlPort on a clean Julia installation and is useful for development purposes. For using this package in production, it is better to include it in your Julia registry.

Clone this git repository.

Open a Julia shell:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

Type a ] character to open a "pkg" subshell.

(v1.0) pkg>

Install the ErlPort package.

ErlPorts is not a registered package yet, so it can be installed as described in the Adding unregistered packages section of the Julia documentation.

In this example we will use our local clone, but you can also specify the GitHub URL and branch name (see the documentation section above).

(v1.0) pkg> add /local/path/to/ErlPort.jl

   Cloning default registries into /home/hcs/.julia/registries
   Cloning registry General from "https://github.com/JuliaRegistries/General.git"
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Cloning git-repo `/home/hcs/w/julia/ErlPort.jl`
  Updating git-repo `/home/hcs/w/julia/ErlPort.jl`
 Resolving package versions...
  Updating `~/.julia/environments/v1.0/Project.toml`
  [572bf9c6] + ErlPort v0.4.0 #many-improvements (/home/hcs/w/julia/ErlPort.jl)
  Updating `~/.julia/environments/v1.0/Manifest.toml`
  [572bf9c6] + ErlPort v0.4.0 #many-improvements (/home/hcs/w/julia/ErlPort.jl)
  [2a0f44e3] + Base64
  [8ba89e20] + Distributed
  [b77e0a4c] + InteractiveUtils
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [9a3f8284] + Random
  [9e88b42a] + Serialization
  [6462fe0b] + Sockets
  [8dfed614] + Test

Hit "backspace" to close the "pkg" subshell.

Usage

The following example shows how to use ErlPort to encode Julia objects into external term format and decode them from external term format:

julia> import ErlPort
[ Info: Precompiling ErlPort [572bf9c6-b013-11e8-0682-13c52dd2789a]

julia> list = [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

julia> encoded = ErlPort.encode(list)
13-element Array{UInt8,1}:
 0x83
 0x6c
 0x00
 0x00
 0x00
 0x03
 0x61
 0x01
 0x61
 0x02
 0x61
 0x03
 0x6a

julia> ErlPort.decode(encoded)
3-element Array{Int64,1}:
 1
 2
 3

The contents of the encoded byte sequence can be read natively in Erlang:

~$ erl
Erlang/OTP 21 [erts-10.0.8] [source] [64-bit] [smp:4:4] [ds:4:4:10]
[async-threads:4] [hipe]

Eshell V10.0.8  (abort with ^G)

% The `Encoded` variable has the exact same bytes as the `encoded` variable in
% the Julia shell above.
1> Encoded = <<"\x83\x6c\x00\x00\x00\x03\x61\x01\x61\x02\x61\x03\x6a">>.
<<131,108,0,0,0,3,97,1,97,2,97,3,106>>

2> List = binary_to_term(Encoded).
[1,2,3]

A note on representation

Sometimes the same data can have multiple representation in External term format. E.g. both the <<131,108,0,0,0,3,97,1,97,2,97,3,106>> and <<131,107,0,3,1,2,3>> byte sequences in External Term Format represent the [1,2,3] list.

As we see in the example above, ErlPort chooses the former representation. Erlang's term_to_binary function chooses the latter:

erlang> term_to_binary([1,2,3]).
<<131,107,0,3,1,2,3>>

This doesn't cause any problem, this representation is also recognized by ErlPort:

julia> ErlPort.decode(b"\x83\x6b\x00\x03\x01\x02\x03")
3-element Array{UInt8,1}:
 0x01
 0x02
 0x03

Unit tests

Start the Julia shell and type a ] character to open a "pkg" subshell.

$ julia
[...]
(v1.0) pkg>

Type test ErlPort:

(v1.0) pkg> test ErlPort   
Testing ErlPort   
[...]
Testing ErlPort tests passed

Type Conversions

Erlang to Julia

ErlangJulia
truetrue
falsefalse
undefinednothing
nanNaN
an_atom:an_atom
33 (Int64)
3.143.14 (Float64)
<<"str">>b"str"
[1,2,3][1,2,3]
{a,b,c}(:a,:b,:c)
#{1 => 2}Dict(1 => 2)

Julia to Erlang

JuliaErlang
truetrue
falsefalse
nothingundefined
NaNnan
:an_atoman_atom
3 (Int64)3
3.14 (Float64)3.14
"str"<<"str">>
b"str"<<"str">>
[1,2,3][1,2,3]
(:a,:b,:c){a,b,c}
Dict(1 => 2)#{1 => 2}

Author: Billosys
Source Code: https://github.com/billosys/ErlPort.jl 
License: View license

#julia #format