Skip to content

Commit

Permalink
- disabling EXNN.Utils.Logger, think of a better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Oct 18, 2015
1 parent 49c2c25 commit 5519262
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
language: elixir
otp_release:
- 17.4
- 18.0
elixir:
- 1.1.1
2 changes: 1 addition & 1 deletion lib/exnn/connectome.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule EXNN.Connectome do
"""

alias EXNN.Utils.Random
import EXNN.Utils.Logger
# import EXNN.Utils.Logger

# TODO: decouple storage from link/patterns
# into Connectome.Links and Connectome.Pattern
Expand Down
1 change: 0 additions & 1 deletion lib/exnn/events/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ defmodule EXNN.Events.Manager do
{:ok, messages}
end


end
2 changes: 1 addition & 1 deletion lib/exnn/node_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule EXNN.NodeServer do
defmacro __using__(options) do
quote do
use GenServer
import EXNN.Utils.Logger
# import EXNN.Utils.Logger

def start_link(genome) do
GenServer.start_link(__MODULE__, genome, name: genome.id)
Expand Down
2 changes: 1 addition & 1 deletion lib/exnn/trainer/mutations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule EXNN.Trainer.Mutations do
alias EXNN.Trainer.Mutations.Set
alias EXNN.Trainer.Mutations.Agent

import EXNN.Utils.Logger
# import EXNN.Utils.Logger

def start_link do
GenServer.start_link __MODULE__,
Expand Down
2 changes: 1 addition & 1 deletion lib/exnn/trainer/mutations/agent.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule EXNN.Trainer.Mutations.Agent do
@moduledoc false
import EXNN.Utils.Logger
# import EXNN.Utils.Logger
alias EXNN.Trainer.Mutations.Set.Mutation

def apply mutation_set do
Expand Down
4 changes: 2 additions & 2 deletions lib/exnn/trainer/mutations/set.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule EXNN.Trainer.Mutations.Set do
@moduledoc false
import EXNN.Utils.Logger
# import EXNN.Utils.Logger

alias EXNN.Utils.Math
alias EXNN.Utils.Random
Expand Down Expand Up @@ -56,7 +56,7 @@ defmodule EXNN.Trainer.Mutations.Set do
defstruct type: nil, id: nil, changes: []

def new(genome, type: type) do
log "MUTATE:", {genome.id, type}, :debug
# log "MUTATE:", {genome.id, type}, :debug
struct(__MODULE__, [type: type, id: genome.id]) |> build_changes(genome)
end

Expand Down
7 changes: 5 additions & 2 deletions lib/exnn/trainer/sync.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule EXNN.Trainer.Sync do
use GenServer
import EXNN.Utils.Logger
# # import EXNN.Utils.Logger
import Logger

alias EXNN.Trainer.Mutations

@tolerance 0.001
Expand Down Expand Up @@ -67,7 +69,8 @@ defmodule EXNN.Trainer.Sync do
end
Mutations.step
schedule_training_task state.sensors
log "STATS:", state, :info
# log "STATS:", state, :info
Logger.info "#{inspect state}"
{:reply, :ok, %{new_state | counter: new_state.counter + 1}}
end

Expand Down
14 changes: 10 additions & 4 deletions lib/exnn/utils/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ defmodule EXNN.Utils.Logger do
# quote location: :keep do
# end
# end
require Elixir.Logger, as: Logger

defmacro log(head, inspected, level\\:warn) do
# defmacro log(head, inspected, level\\:warn) do
# quote do
# require Elixir.Logger, as: Logger
# end

# NOTE: Logger.log/? was removed in Elixir 1.1
Macro.expand "Logger.#{level} \"#{head}\n#{inspect inspected}\"", __ENV__
end
# Macro.expand "Logger.#{level} \"#{head}\n#{inspect inspected}\"", __ENV__

# FIXME: worst choice ever
# Code.eval_string("Logger.#{level}(\"#{head}\n#{inspect inspected}\")")
# end
end
2 changes: 1 addition & 1 deletion lib/exnn/utils/random.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EXNN.Utils.Random do
@moduledoc false
# NOTE: Randomness is NOT Math
import EXNN.Utils.Logger
# import EXNN.Utils.Logger
import EXNN.Utils.Math, only: [pi: 0]

def seed do
Expand Down
6 changes: 3 additions & 3 deletions test/examples/xor.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule XORTest do

test "X or runs!" do
:ok = EXNN.Trainer.start
:timer.sleep 5000
:timer.sleep 3000
end
end

Expand Down Expand Up @@ -68,7 +68,7 @@ end
defmodule XORApp.Fitness do
@domain [{-1, -1}, {-1, 1}, {1, -1}, {1, 1}]
alias EXNN.Utils.Math
import EXNN.Utils.Logger
# import EXNN.Utils.Logger

use EXNN.Fitness, state: [
trigger: @domain,
Expand All @@ -86,7 +86,7 @@ defmodule XORApp.Fitness do

def distance_squared(state) do
acc = state.acc
log "computed: ", acc
# log "computed: ", acc
acc |> Enum.map(&diff_squared/1) |> Enum.sum # |> Math.sqrt
end

Expand Down
4 changes: 2 additions & 2 deletions test/exnn/trainer/mutations_test.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule EXNN.Trainer.MutationsTest do
alias EXNN.Trainer.Mutations.Set
alias EXNN.Trainer.Mutations.Agent
import EXNN.Utils.Logger
# import EXNN.Utils.Logger

use ExUnit.Case

setup_all do
{_maybe_ok, _pid} = HostApp.start(:normal, [])
{_maybe_started, _pid} = HostApp.start(:normal, [])
on_exit(fn -> HostApp.stop(:normal) end)
:ok
end
Expand Down
2 changes: 1 addition & 1 deletion test/exnn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule EXNNTest do
Integrative Testing of a remote applicaion
"""
setup_all do
{_maybe_ok, _pid} = HostApp.start(:normal, [])
{_maybe_started, _pid} = HostApp.start(:normal, [])

on_exit fn ->
HostApp.stop(:normal)
Expand Down

0 comments on commit 5519262

Please sign in to comment.