Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Major revamp #1487

Closed
wants to merge 253 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
253 commits
Select commit Hold shift + click to select a range
7259886
add duration to log messages
mwartell Feb 8, 2022
7ceee65
initial no-docker bits setup
Feb 8, 2022
90ec4ad
Merge branch 'logging-improvement' of github.com:shenshaw26/armory in…
Feb 8, 2022
30273f8
adding no-docker runs to pytest suite
Feb 8, 2022
77cf94d
removing interactive use case
Feb 8, 2022
04e1552
Updating ci file to run on demand
Feb 8, 2022
f3ebc50
messing with ci
Feb 8, 2022
7ff0c7f
updating docs
Feb 8, 2022
1d04810
Adding interactive tests back
Feb 8, 2022
be4a512
removing test_logs example
Feb 8, 2022
dbed0b9
Cleaning up flake config
Feb 9, 2022
2f89c04
Adding more verbosity on git pre-commit hooks
Feb 9, 2022
9d06390
more docs update
Feb 9, 2022
28d62f2
full excision of all logging and colored logs use
mwartell Feb 9, 2022
296a2b6
rollback version to develop to unbreak CI
mwartell Feb 9, 2022
652a606
review and flake8 corrections
mwartell Feb 9, 2022
7bdcd99
updating docs and renaming requirements file and fixed flake issue
Feb 9, 2022
e6226cf
log/logger name collision cleared
mwartell Feb 9, 2022
0148fd0
ci uses new no-docker-requirement.txt
mwartell Feb 9, 2022
45f98a4
Removing unnecessary req, see comments from https://github.com/twosix…
Feb 10, 2022
37e81a2
experiment pin numpy version as in tf1/Dockerfile
mwartell Feb 10, 2022
8395e57
Revert "experiment pin numpy version as in tf1/Dockerfile"
mwartell Feb 10, 2022
ff1d2da
Addressing PR1271 comments
Feb 10, 2022
44d4ffb
Merge branch 'logging-improvement' of github.com:shenshaw26/armory in…
Feb 10, 2022
4c058b9
add loguru install to dockerfiles
mwartell Feb 10, 2022
4c98f23
Merge branch 'logging-improvement' of github.com:shenshaw26/armory in…
mwartell Feb 10, 2022
44757a8
Addressing PR1271 comments
Feb 10, 2022
7966a20
Addressing PR1271 comments
Feb 10, 2022
535be17
Addressing PR1271 comments
Feb 10, 2022
a76bb2a
More doc updates for PR
Feb 10, 2022
abc6f6d
intercept and log other libraries calls to logging
mwartell Feb 11, 2022
7bf22ac
logs documentation
mwartell Feb 11, 2022
e0c53b6
Revert "add loguru install to dockerfiles"
mwartell Feb 11, 2022
2b20ec8
minor updates to comments / docs
Feb 11, 2022
4087561
added back in loguru, but pip not conda
mwartell Feb 11, 2022
5476500
add loguru to pip install for all dockerfiles
mwartell Feb 11, 2022
5f87c0d
could it be as easy as pinning numpy version
mwartell Feb 11, 2022
d4df562
Revert "could it be as easy as pinning numpy version"
mwartell Feb 11, 2022
8dc203c
fix tf2 ci test
davidslater Feb 11, 2022
0517162
Merge branch 'fix-ci-2227' into logging-improvement
mwartell Feb 12, 2022
3f81383
Merge branch 'logging-improvement' of github.com:shenshaw26/armory in…
mwartell Feb 12, 2022
e997ee1
first cut logging docs
mwartell Feb 13, 2022
cf4d50a
fix argument error
mwartell Feb 14, 2022
d837fd5
fixing minor doc comment
Feb 14, 2022
eef41aa
broken commit - moving to unified log-level
mwartell Feb 14, 2022
6389638
bump release version
mwartell Feb 14, 2022
c7b31ba
Merge branch 'logging-improvement' of github.com:shenshaw26/armory in…
mwartell Feb 14, 2022
17513a0
Revert "broken commit - moving to unified log-level"
mwartell Feb 14, 2022
7ee3e57
calm messages from chatty modules
mwartell Feb 14, 2022
91e44e3
bump version in scenarios
mwartell Feb 15, 2022
f4694ff
broken - logging filters start
mwartell Feb 15, 2022
b920ba6
broken - added --log-level option
mwartell Feb 15, 2022
70d2cee
add callchain doc
mwartell Feb 16, 2022
4855dfc
getting CI setup
Feb 16, 2022
ab7521a
logging function decorator
mwartell Feb 16, 2022
7494f8e
third try
Feb 16, 2022
0004844
Getting Docker Square... no longer going to support tf1 or deepspeech
Feb 16, 2022
373f1b6
pass filter settings to subordinate python
mwartell Feb 17, 2022
6b88e51
address all pr #1271 comments
mwartell Feb 17, 2022
be66da4
Merge pull request #2 from mwartell/logging-filters
mwartell Feb 17, 2022
d37f982
Updating tests to get datasets working
Feb 17, 2022
79b2728
Merge branch 'logging-improvement' into primo
mwartell Feb 17, 2022
4e0c095
fix comment typo
mwartell Feb 17, 2022
b125c80
flake8 ci unref import fix
mwartell Feb 17, 2022
c59d3d9
small refactor to make more general
Feb 17, 2022
2736578
flake8 undef name fix
mwartell Feb 17, 2022
3dc6ac5
First stab at models
Feb 17, 2022
2cb419f
Merging Primo
Feb 17, 2022
0433f65
Merge branch 'primo' into config-object
mwartell Feb 17, 2022
2bfa688
added more model tests
Feb 17, 2022
c04fb07
added more model tests
Feb 17, 2022
7b9fa28
first draft configuration object
mwartell Feb 18, 2022
1a98b44
fix comment typo
mwartell Feb 18, 2022
207fd08
removed global config in favor of actual argument
mwartell Feb 18, 2022
a8a9948
updating datasets test and adding to CI
Feb 18, 2022
e3146bd
Initial hack at test_models.py
Feb 19, 2022
e4f12fa
updating notes
Feb 19, 2022
a7b4f31
Cleaning up test_host
Feb 19, 2022
980a8a8
adding notes
Feb 19, 2022
f854dc4
Cleaning up test_docker
Feb 19, 2022
a1bbe4d
Cleaning up test_docker
Feb 19, 2022
072232b
Refactor test_host/test_external_repo and tests/test_docker/test_weig…
Feb 19, 2022
a85c665
Updating tests/test_datasets.py to include split_index
Feb 22, 2022
4a368a9
cleaning up dataset tests
Feb 22, 2022
7028400
moving test_metrics to top level
Feb 22, 2022
e14f057
cleanup
Feb 22, 2022
360fda8
more simple refactor
Feb 22, 2022
e18b32e
merging in relevant bits from slater tf1 deprecation branch
Feb 22, 2022
d8a5fd3
Merge branch 'develop' into primo
mwartell Feb 22, 2022
5462b5a
Test refactor complete...first attempt at getting CI to work
Feb 22, 2022
52c2b00
fixing tests and docs
Feb 22, 2022
db4dbc3
fixing up docker file
Feb 22, 2022
1688ed5
another error
Feb 22, 2022
37a08c1
gotta build base for now
Feb 22, 2022
d6c2219
launcher app spec
mwartell Feb 22, 2022
13c50cc
use log name for uniformity
mwartell Feb 22, 2022
bd99699
fixing tests and ci
Feb 23, 2022
162bd67
more app docs
mwartell Feb 23, 2022
975327d
another try
Feb 23, 2022
48ce22e
another try
Feb 23, 2022
c41e778
add progress log level
mwartell Feb 23, 2022
c5e5a77
updating tools
Feb 23, 2022
5873433
one more
Feb 23, 2022
9eb1a52
one more
Feb 23, 2022
388d816
merging in current develop
Feb 23, 2022
0ec713a
Cleanup from merge and adding pytorch-deepspeech docker
Feb 23, 2022
9a599e5
making progress
Feb 24, 2022
b1f7705
minor log tweaks based on real runs
mwartell Feb 24, 2022
aca9a6b
make docker error message match build.sh
mwartell Feb 24, 2022
981c70f
made the logging planning doc current
mwartell Feb 24, 2022
958eb64
initial hack at pydantic experiment
Feb 25, 2022
54486ae
initial hack at pydantic experiment
Feb 25, 2022
c134b44
Initial stab at environment
Feb 25, 2022
3aa0c3a
Adding quick check
Feb 25, 2022
a5f6cdc
minor update
Feb 25, 2022
dcd0875
Saving State
Feb 25, 2022
2b5fc9c
Saving State
Feb 25, 2022
ccee12d
minor cleanup to get tests better
Feb 25, 2022
669114f
new thing
Feb 25, 2022
ba1fefb
fixing pre-commit crap
Feb 25, 2022
876c19b
I think its working
Feb 25, 2022
1647356
pytest spec in ci_test.yml was wrong...correcting
Feb 25, 2022
3e3968b
one last fix on docker side
Feb 25, 2022
1fe3e72
minor update to build script documentation
Feb 26, 2022
df59560
initial hack at manual container push
Feb 26, 2022
7e968b5
trying from github
shenshaw26 Feb 26, 2022
c6a7bfc
removing locally
Feb 26, 2022
f273cb1
Merge pull request #7 from shenshaw26/shenshaw26-patch-1
shenshaw26 Feb 26, 2022
f3057ca
minor tweak
Feb 26, 2022
91173b2
fix workflow
Feb 26, 2022
d2f44aa
Initial start...not working yet but close
Feb 27, 2022
c22adec
saving state
Feb 28, 2022
77a4ecc
minor update
Feb 28, 2022
f2be46c
saving state
Mar 1, 2022
01b8289
Initial setup working...now to see if all tests work
Mar 1, 2022
9d44ce0
Removing explicit armory version deps in scenario configs
Mar 1, 2022
0d5be0e
Updating Test to make it pass (no longer makes sense to do that check
Mar 1, 2022
ea3286f
Adding some helpful log messages
Mar 1, 2022
c650673
trying to pip install in test_configuration bit
Mar 1, 2022
f1307b3
addressing review comments
Mar 1, 2022
14fe94b
Fixing build tag from armory version
Mar 1, 2022
560601f
Addressing PR comments
Mar 1, 2022
c70ac1e
adding docs for pr
Mar 1, 2022
84ed6b7
adding armory configure to ci tests
Mar 1, 2022
24a933b
another attempt at armory configure
Mar 1, 2022
112a71f
another try
Mar 1, 2022
98fd5aa
another try
Mar 1, 2022
6a74f03
I hate broken pipes
Mar 1, 2022
b1b2e79
I hate broken pipes
Mar 1, 2022
f42ef50
gave up just added to armory configure '--use-defaults' flag
Mar 1, 2022
da92b10
Adding back all tests
Mar 1, 2022
c7a8392
this one is for all the marbles
Mar 2, 2022
768f824
Fixing test to work with new version
Mar 2, 2022
bccd26d
fix broken default
mwartell Mar 2, 2022
9bc16bf
this makes sense to me
mwartell Mar 2, 2022
78509ed
WIP: Update Armory to use `setuptools_scm` (#8)
shenshaw26 Mar 2, 2022
cbe701e
Updating small bits and skipping docker_build test when inside docker
Mar 2, 2022
e4b8c4d
Merge branch 'use-scm' of github.com:shenshaw26/armory into use-scm
Mar 2, 2022
af68451
minor format
Mar 2, 2022
6802123
put container id in shutdown message
mwartell Mar 2, 2022
f2bfc7c
scrap the interface prototype
mwartell Mar 2, 2022
a8e124d
merging
Mar 2, 2022
151e321
Trying to Get the merge to have the right bits
Mar 2, 2022
35c2e4d
Merging primo into current
Mar 2, 2022
86925cf
Adding todos
Mar 2, 2022
d3e4bcd
Merge remote-tracking branch 'shenshaw/duo' into config-object
mwartell Mar 2, 2022
b0a95ce
Merge pull request #4 from shenshaw26/config-object
mwartell Mar 2, 2022
7bc840a
a helpful check when testing optional cuda support
mwartell Feb 28, 2022
cf6a5c6
duo is the new primo in CI
mwartell Mar 2, 2022
6d44e0c
fix a flake8 report
mwartell Mar 2, 2022
ea7c1fb
saving state
Mar 3, 2022
c9b673c
saving state
Mar 4, 2022
04063f8
Merge remote-tracking branch 'origin/develop' into duo
mwartell Mar 7, 2022
8c51555
Got Env setup going
Mar 7, 2022
96cfe77
cleanup
Mar 7, 2022
fd349cf
Getting Basic Experiment Idea fleshed out
Mar 7, 2022
c9c9f6c
saving state
Mar 8, 2022
d0b7f7b
saving state
Mar 8, 2022
ecfb04e
adding end2end cron
Mar 8, 2022
0f81454
testing
Mar 8, 2022
af68934
try again
Mar 8, 2022
dd71cf7
3rd try
Mar 8, 2022
2672258
adding needs job
Mar 8, 2022
44c7466
adding needs job no build
Mar 8, 2022
1600791
fixing up
Mar 8, 2022
0741234
another try:
Mar 8, 2022
6a5e5ca
Trying different tag mechanism
Mar 8, 2022
86e8bdc
just trying passin value
Mar 8, 2022
4508bc2
another try
Mar 8, 2022
c2e759f
I think its working
Mar 8, 2022
eeb578c
fixing pytest to use markers (-m) properly
Mar 8, 2022
90d67fb
Cleaning up
Mar 8, 2022
7d382c7
another shot
Mar 8, 2022
9b308a9
fixing pycache issue
Mar 8, 2022
f007c33
fixing docker ci tests
Mar 8, 2022
0ad9037
fixing weird bug
Mar 8, 2022
3beff6b
last try for the day
Mar 8, 2022
3862233
Adding note
Mar 9, 2022
4d5c597
making runner logs more verbose
Mar 9, 2022
4fe18b2
trying single run on end2end
Mar 9, 2022
4ffb615
trying single run on end2end
Mar 9, 2022
40a94fe
just trying unit tests in docker on local runner
Mar 9, 2022
5af9a45
Putting everything back to try with local runner on noether
Mar 9, 2022
5d5226f
try again
Mar 9, 2022
b7aa63c
Merge branch 'duo' into update_armory
Mar 10, 2022
b4aa1c5
merging tiga -> update_armory
Mar 17, 2022
49881c4
adding CI bits for tiga
Mar 17, 2022
0a826c9
making it a todo
Mar 17, 2022
83b424e
Merge branch 'develop' into tiga
mwartell Mar 18, 2022
f41d326
Merge remote-tracking branch 'origin/develop' into tiga
mwartell Mar 25, 2022
82abff6
Merge branch 'tiga' into update_armory
mwartell Mar 25, 2022
07d4adc
afraid of breaking what works right now
mwartell Mar 30, 2022
845e5bb
added platform group
mwartell Mar 31, 2022
7b817f0
add other requirements
mwartell Mar 31, 2022
d3e0e04
manifest is not needed
mwartell Mar 31, 2022
caf3f50
add setuptools_scm to setup
mwartell Mar 31, 2022
a6e606c
restore old armory main
mwartell Mar 31, 2022
ee15952
working the package definition
mwartell Mar 31, 2022
fda4fe4
imports now work for launcher and engine
mwartell Apr 1, 2022
25cc602
Merge remote-tracking branch 'origin/develop' into launcher-1384
mwartell Apr 1, 2022
9ca07ad
Merge pull request #3 from mwartell/launcher-1384
mwartell Apr 1, 2022
863661c
stash
mwartell Apr 18, 2022
ef1d305
supplanted by setup.cfg
mwartell Apr 18, 2022
9b67221
supplanted by setup.cfg
mwartell Apr 18, 2022
b5e1d44
junk file accidentally commited
mwartell Apr 18, 2022
c083a3c
adding new docker runner
Apr 29, 2022
64ddbe1
first stab
Apr 29, 2022
d50c60f
saving state
May 2, 2022
07d5513
got the rsettr bits working
May 2, 2022
47852dc
Updating documentation and utilizing for experiment parameters
May 2, 2022
7fea0c9
saving state
May 2, 2022
4db4d42
saving state
May 2, 2022
3d80805
First Successgit add . Ran with command: armory-launcher -v run ./te…
May 3, 2022
3469925
updating to black 22.3 and saving state
May 4, 2022
a3bc344
updating environment to include ref to armory source tree
May 9, 2022
56bdcff
Now working in both native and docker mode.... docker mode is a bit s…
May 9, 2022
c1c5176
updating pytorch docker container to work with new bits
May 9, 2022
a382566
adding click to deps
hensh2ss May 9, 2022
b722d8b
updating docs and cleaning up
May 9, 2022
755136b
Merge branch 'major-revamp' of github.com:shenshaw26/armory into majo…
May 9, 2022
a004e3e
removing empty webapi
May 11, 2022
668021e
moving eval/plot things to new submodule called postprocessing. Thes…
May 11, 2022
ff82404
getting basic notebook setup going
May 11, 2022
c803be9
saving state
May 11, 2022
624e3cc
change bare template strings to quoted
mwartell May 12, 2022
5dde3b7
add sentinel and docker mode filter dumps
mwartell May 12, 2022
3ee71c9
add execution guard to template
mwartell May 12, 2022
1f055af
fix template guard
mwartell May 12, 2022
ce1da57
decode False filters properly
mwartell May 12, 2022
f0af9e5
Merge pull request #16 from shenshaw26/fix-template-syntax
mwartell May 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci_test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
name: CI Tests

# TODO: Update this before merge into twosixlabs/armory to remove tiga ref
on:
push:
branches:
- master
- develop
- tiga

pull_request:
branches:
- master
- develop
- tiga

workflow_dispatch:

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/end2end_cron.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
name: End-to-End Tests

# TODO: Update this before merge into twosixlabs/armory to remove tiga ref
on:
push:
branches:
- master
- develop
- tiga

pull_request:
branches:
- master
- develop
- tiga
schedule:
- cron: 0 0 * * * # At Midnight Every Day

Expand Down
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

4 changes: 4 additions & 0 deletions armory-base-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ ffmpeg-python==0.2.0

# Needed for CARLA baseline scenario
opencv-python==4.5.5.62

# Needed for Experiment / Environment parsing
pydantic
pyyaml
121 changes: 0 additions & 121 deletions armory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,121 +0,0 @@
"""Adversarial Robustness Evaluation Test Bed

ARMORY Versions use "Semantic Version" scheme where stable releases will have versions
like `0.14.6`. Armory uses `setuptools_scm` which pulls the version from the tags most
recent git tag. For example if the most recent git tag is `v0.14.6`, then the version
will be `0.14.6`.

If you are a developer, the version will be constructed from the most recent tag plus a
suffix of gHASH where HASH is the short hash of the most recent commit. For example,
if the most recent git tag is v0.14.6 and the most recent commit hash is 1234567 then
the version will be 0.14.6.g1234567. This scheme does differ from the scm strings
which also have a commit count and date in them like 1.0.1.dev2+g0c5ffd9.d20220314181920
which is a bit ungainly.
"""

try:
from importlib.metadata import version, PackageNotFoundError
except ModuleNotFoundError:
from importlib_metadata import version, PackageNotFoundError

import pathlib
import re
import subprocess

from armory.logs import log


def get_dynamic_version():
"""
Produce the version dynamically from setup.py if available.

Return None if setup.py is not available
"""
armory_repo_root = pathlib.Path(__file__).parent.parent
setup = armory_repo_root / "setup.py"
if not setup.is_file():
return None

completed = subprocess.run(
["python", str(setup), "--version"],
cwd=str(armory_repo_root),
capture_output=True,
text=True,
)
try:
completed.check_returncode()
except subprocess.CalledProcessError:
log.critical("setup.py exists but 'python setup.py --version' failed.")
raise
version = completed.stdout.strip()
return version


__version__ = get_dynamic_version()
if __version__ is None:
try:
__version__ = version("armory-testbed")
except PackageNotFoundError:
log.critical("armory package is not pip installed and not locally cloned")
raise
__version__ = re.sub(r"dev\d+\+(g[0-9a-f]+)(\.d\d+)?$", r"\1", __version__)


# Handle PyTorch / TensorFlow interplay

# import torch before tensorflow to ensure torch.utils.data.DataLoader can utilize
# all CPU resources when num_workers > 1
try:
import torch # noqa: F401
except ImportError:
pass

# From: https://www.tensorflow.org/guide/gpu#limiting_gpu_memory_growth
try:
import tensorflow as tf

gpus = tf.config.list_physical_devices("GPU")
if gpus:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
log.info("Setting tf.config.experimental.set_memory_growth to True on all GPUs")
except RuntimeError:
log.exception("Import armory before initializing GPU tensors")
raise
except ImportError:
pass

# Handle ART configuration

from armory import paths

try:
paths.set_art_data_path()
except OSError:
# If running in --no-docker mode, catch write error based on default DockerPaths
# the later call to paths.set_mode("host") will set this properly
pass

# typedef for a widely used JSON-like configuration specification
from typing import Dict, Any

Config = Dict[str, Any]

# Submodule imports
try:
from armory import art_experimental
from armory import baseline_models
from armory import data
from armory import docker
from armory import eval
from armory import paths
from armory import utils
from armory import webapi
except ImportError as e:
module = e.name
print(f"ERROR: cannot import '{module}' module")
print(" Please run: $ pip install -r requirements.txt")
raise

END_SENTINEL = "Scenario has finished running cleanly"
1 change: 0 additions & 1 deletion armory/art_experimental/attacks/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion armory/art_experimental/defences/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions armory/art_experimental/poison_detection/__init__.py

This file was deleted.

File renamed without changes.
201 changes: 201 additions & 0 deletions armory/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
"""Adversarial Robustness Evaluation Test Bed

ARMORY Versions use "Semantic Version" scheme where stable releases will have versions
like `0.14.6`. Armory uses `setuptools_scm` which pulls the version from the tags most
recent git tag. For example if the most recent git tag is `v0.14.6`, then the version
will be `0.14.6`.

If you are a developer, the version will be constructed from the most recent tag plus a
suffix of gHASH where HASH is the short hash of the most recent commit. For example,
if the most recent git tag is v0.14.6 and the most recent commit hash is 1234567 then
the version will be 0.14.6.g1234567. This scheme does differ from the scm strings
which also have a commit count and date in them like 1.0.1.dev2+g0c5ffd9.d20220314181920
which is a bit ungainly.
"""

# try:
# from importlib.metadata import version, PackageNotFoundError
# except ModuleNotFoundError:
# from importlib_metadata import version, PackageNotFoundError # noqa
#
import pathlib
import re
import subprocess

# from armory.logs import log
#
#
# def get_dynamic_version():
# """
# Produce the version dynamically from setup.py if available.
#
# Return None if setup.py is not available
# """
# armory_repo_root = pathlib.Path(__file__).parent.parent
# setup = armory_repo_root / "setup.py"
# if not setup.is_file():
# return None
#
# completed = subprocess.run(
# ["python", str(setup), "--version"],
# cwd=str(armory_repo_root),
# capture_output=True,
# text=True,
# )
# try:
# completed.check_returncode()
# except subprocess.CalledProcessError:
# log.critical("setup.py exists but 'python setup.py --version' failed.")
# raise
# version = completed.stdout.strip()
# return version

#
# __version__ = get_dynamic_version()
# if __version__ is None:
# try:
# __version__ = version("armory-testbed")
# except PackageNotFoundError:
# log.critical("armory package is not pip installed and not locally cloned")
# raise
# __version__ = re.sub(r"dev\d+\+(g[0-9a-f]+)(\.d\d+)?$", r"\1", __version__)
#

from armory.logs import log
import os


def _load_torch_and_tf():
"""Handle Loading PyTorch / Tensorflow
In order for armory to work properly, we need to
import torch at the very beginning, especially before
tensorflow to ensure torch.utils.data.DataLoader can utilize
all CPU resources when num_workers > 1
"""
log.debug("Loading PyTorch/Tensorflow")
try:
import torch # noqa: F401
except ImportError:
log.warning("Torch not found! Disregard if using tf backend")
pass

log.debug("Loading Tensorflow")
try:
import tensorflow as tf

gpus = tf.config.list_physical_devices("GPU")
if gpus:
# Currently, memory growth needs to be the same across GPUs
log.info(
f"Found GPUs: {gpus}...setting tf.config.experimental.set_memory_growth to True on all GPUs"
)
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
except RuntimeError:
log.exception("Import armory before initializing GPU tensors")
raise
except ImportError:
# TODO Figure out if this is actually true give TFDS dep.
log.warning("Tensorflow not found! Disregard if using pure pytorch backend")
pass


def _set_art_data_path():
saved_model_paths = os.getenv("ARMORY_PATHS_SAVED_MODELS_DIRECTORY")
art_path = os.path.join(saved_model_paths, "art")
log.info(f"Setting ART Data PATH to {art_path}")
try:
from art import config

config.set_data_path(art_path)
except ImportError:
log.warning("ART not found...")
pass


def _load_engine_deps():

# TODO: Currently this is a requirement of armory.engine...
# However, we need to remove this dep as we move forward
from typing import Dict, Any

global Config
Config = Dict[str, Any]

# Submodule imports
try:
from armory.engine import art_experimental, baseline_models, docker, eval
from armory.engine import data
from armory.engine import paths
from armory.engine import utils
except ImportError as e:
module = e.name
print(f"ERROR: cannot import '{module}' module")
print(" Please run: $ pip install -r requirements.txt")
raise

END_SENTINEL = "Scenario has finished running cleanly" # noqa F841


# ----------- Executing All Necessary Components below (ORDER MATTERS!!) ----------
log.info("Initiating Armory Engine...")
_load_torch_and_tf()
_set_art_data_path()
_load_engine_deps()


# Handle PyTorch / TensorFlow interplay

# import torch before tensorflow to ensure torch.utils.data.DataLoader can utilize
# all CPU resources when num_workers > 1
# try:
# import torch # noqa: F401
# except ImportError:
# pass

# From: https://www.tensorflow.org/guide/gpu#limiting_gpu_memory_growth
# try:
# import tensorflow as tf
#
# gpus = tf.config.list_physical_devices("GPU")
# if gpus:
# # Currently, memory growth needs to be the same across GPUs
# for gpu in gpus:
# tf.config.experimental.set_memory_growth(gpu, True)
# log.info("Setting tf.config.experimental.set_memory_growth to True on all GPUs")
# except RuntimeError:
# log.exception("Import armory before initializing GPU tensors")
# raise
# except ImportError:
# pass

# Handle ART configuration

# from armory.engine import paths
#
# try:
# paths.set_art_data_path()
# except OSError:
# # If running in --no-docker mode, catch write error based on default DockerPaths
# # the later call to paths.set_mode("host") will set this properly
# pass

# typedef for a widely used JSON-like configuration specification
# from typing import Dict, Any
#
# Config = Dict[str, Any]

# # Submodule imports
# try:
# from armory.engine import art_experimental, baseline_models, docker, eval
# from armory.engine import data
# from armory.engine import paths
# from armory.engine import utils
# from armory.engine import webapi
# except ImportError as e:
# module = e.name
# print(f"ERROR: cannot import '{module}' module")
# print(" Please run: $ pip install -r requirements.txt")
# raise
#
# END_SENTINEL = "Scenario has finished running cleanly"
Loading