Skip to content

Instantly share code, notes, and snippets.

View mfalt's full-sized avatar

Mattias Fält mfalt

View GitHub Profile
@mfalt
mfalt / benchmark.jl
Created March 27, 2019 19:52
benchmark in proximal operators, osqp vs qpdas
using ProximalOperators, Random
# Number of variables
n = 1000
# Number of halfspaces
mi = 50 # Inequalities with C
me = 50 # Equalities with A
Random.seed!(1)
# One point in polytope
x0 = randn(n)
@mfalt
mfalt / PlotTestCommenter
Created March 26, 2020 23:38
PlotTestCommenter
#### Test Plots
using ControlExamplePlots
using Plots
gr()
default(show=false)
funcs, refs, eps = getexamples()
# Make it easier to pass tests on different systems
# Set to a factor 2 of common errors
eps = [0.15, 0.015, 0.1, 0.01, 0.01, 0.02, 0.01, 0.15, 0.15, 0.01, 0.01]
@mfalt
mfalt / dynamics.jl
Created November 19, 2020 13:20
NLOptControl
using Ipopt # Solver
using NLOptControl # Problem definition and discretization
using Plots # Custom plots
# =========== PROBLEM DEFINITION ==============================
# Constraints on states
XL = [-Inf,-Inf,-Inf,-Inf]
XU = [Inf,Inf,Inf,Inf]
# Constraints on control, we will add ux^2+uy^2 <= 1, so these won't be active
# To add packages in the REPL: "]add BenchmarkTools"
using LinearAlgebra, BenchmarkTools
# Simple method and syntax, no types!
function quadratic(x,Q,y)
dot(x,Q*y)
end
Q = randn(5,5)
x = randn(5)
y = randn(5)
module SimpleTreeInterface
export ChildrenFirst, ParentsFirst
export NodeOnly, NodeDepth, NodeIndex
abstract type AbstractReturnMode end
abstract type AbstractTreeIterator{T,RetMode<:AbstractReturnMode} end
struct NodeOnly <: AbstractReturnMode end
struct NodeDepth <: AbstractReturnMode end
using Flux
const nn = gpu(Chain(
Conv((5, 5), 3=>6, relu),
MaxPool((2, 2)),
Conv((5, 5), 6=>16, relu),
MaxPool((2, 2)),
flatten,
Dense(256, 120, relu),
Dense(120, 84, relu),
ERROR: LoadError: TaskFailedException
nested task error: Out of GPU memory trying to allocate 897.217 MiB
Effective GPU memory usage: 52.47% (5.726 GiB/10.913 GiB)
Memory pool usage: 3.117 GiB (3.656 GiB reserved)
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/CUDA/0IDh2/src/pool.jl:219 [inlined]
[2] macro expansion
@ ./timing.jl:299 [inlined]
ERROR: LoadError: TaskFailedException
Stacktrace:
[1] wait
@ ./task.jl:334 [inlined]
[2] fetch(t::Task)
@ Base ./task.jl:349
[3] top-level scope
@ ~/knightvision/piece_recognition/KnightVisionServer/test/test_cuda.jl:39
nested task error: CUDNNError: CUDNN_STATUS_INTERNAL_ERROR (code 4)
# After execution gets stuck, sending `schedule(t, nothing, error=true)` to the task:
Stacktrace:
[1] try_yieldto(undo::typeof(Base.ensure_rescheduled))
@ Base ./task.jl:777
[2] wait()
@ Base ./task.jl:837
[3] wait(c::Base.GenericCondition{ReentrantLock})
@ Base ./condition.jl:123
[4] wait(e::Base.Event)
@ Base ./lock.jl:366