Package restructuring

This commit is contained in:
Chris McCarthy
2023-05-25 10:31:37 +01:00
parent e473c710a2
commit 9bd7aade43
51 changed files with 127 additions and 74 deletions

1
MANIFEST.in Normal file
View File

@@ -0,0 +1 @@
include src/primaite/config/*.yaml

View File

@@ -10,9 +10,9 @@ PrimAITE produces four types of data:
* Outputs - Saved agents * Outputs - Saved agents
* Logging * Logging
Outputs can be found in the *[Install Directory]\\PRIMAITE\\PRIMAITE\\outputs* directory Outputs can be found in the *[Install Directory]\\Primaite\\Primaite\\outputs* directory
Logging can be found in the *[Install Directory]\\PRIMAITE\\PRIMAITE\\logs* directory Logging can be found in the *[Install Directory]\\Primaite\\Primaite\\logs* directory
**Outputs - Results** **Outputs - Results**
@@ -39,4 +39,4 @@ For each training session, assuming the agent being trained implements the *save
**Logging** **Logging**
PrimAITE also provides output logs (for diagnosis) using the Python Logging package. These can be found in the *[Install Directory]\\PRIMAITE\\PRIMAITE\\logs* directory PrimAITE also provides output logs (for diagnosis) using the Python Logging package. These can be found in the *[Install Directory]\\Primaite\\Primaite\\logs* directory

View File

@@ -80,8 +80,8 @@ environment is reset between episodes. Note that the example below should not be
In order to execute a session, carry out the following steps: In order to execute a session, carry out the following steps:
1. Navigate to "[Install directory]\\PRIMAITE\\PRIMAITE\\” 1. Navigate to "[Install directory]\\Primaite\\Primaite\\”
2. Start a console window (type “CMD” in path window, or start a console window first and navigate to “[Install Directory]\\PRIMAITE\\PRIMAITE\\”) 2. Start a console window (type “CMD” in path window, or start a console window first and navigate to “[Install Directory]\\Primaite\\Primaite\\”)
3. Type “python main.py” 3. Type “python main.py”
4. The session will start with an output indicating the current episode, and average reward value for the episode 4. The session will start with an output indicating the current episode, and average reward value for the episode

60
pyproject.toml Normal file
View File

@@ -0,0 +1,60 @@
[build-system]
requires = ["setuptools", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "primaite"
description = "PrimAITE (Primary-level AI Training Environment) is a simulation environment for training AI under the ARCD programme."
authors = [{name="QinetiQ Training and Simulation Ltd"}]
license = {text = "GFX"}
requires-python = ">=3.8"
dynamic = ["version", "readme"]
classifiers = [
"License :: GFX",
"Development Status :: 4 - Beta",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
]
dependencies = [
"gym==0.21.0",
"matplotlib==3.7.1",
"networkx==3.1",
"numpy==1.23.5",
"PyYAML==6.0",
"stable-baselines3==1.6.2"
]
[tool.setuptools.dynamic]
version = {file = ["src/primaite/VERSION"]}
readme = {file = ["README.md"]}
[tool.setuptools]
package-dir = {"" = "src"}
include-package-data = true
license-files = ["LICENSE"]
[project.optional-dependencies]
dev = [
"setuptools==66",
"pytest==7.2.0",
"flake8==6.0.0",
"Sphinx==6.1.3",
"furo==2023.3.27",
"sphinx-code-tabs==0.5.3",
"sphinx-copybutton==0.5.2",
"pytest-cov==4.0.0",
"pytest-flake8==1.1.1",
"pip-licenses==4.3.0",
"wheel==0.38.4",
"build==0.10.0"
]

View File

@@ -1,26 +1,17 @@
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence. # Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
""" from setuptools import setup
Setup from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
"""
from setuptools import find_packages, setup
class bdist_wheel(_bdist_wheel): # noqa
def finalize_options(self): # noqa
super().finalize_options()
# forces whee to be platform and Python version specific
# Source: https://stackoverflow.com/a/45150383
self.root_is_pure = False
setup( setup(
name="primaite", cmdclass={
maintainer="QinetiQ Training and Simulation Ltd", "bdist_wheel": bdist_wheel,
url="https://github.com/qtsl/PrimAITE", }
description="A primary-level simulation tool", )
python_requires=">=3.7",
version="1.1.0",
install_requires=[
"gym==0.21.0",
"matplotlib==3.6.2",
"networkx==2.8.8",
"numpy==1.23.5",
"stable_baselines3==1.6.2",
# Required for older versions of Gym that aren't compliant with
# Setuptools>=67.
"setuptools==66"
],
packages=find_packages()
)

1
src/VERSION Normal file
View File

@@ -0,0 +1 @@
1.2.0

View File

@@ -1,6 +1,6 @@
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence. # Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
""" """
PRIMAITE - main (harness) module Primaite - main (harness) module
Coding Standards: PEP 8 Coding Standards: PEP 8
""" """
@@ -12,9 +12,9 @@ import os.path
import logging import logging
from datetime import datetime from datetime import datetime
from environment.primaite import PRIMAITE from primaite.environment.primaite_env import Primaite
from transactions.transactions_to_file import write_transaction_to_file from primaite.transactions.transactions_to_file import write_transaction_to_file
from common.config_values_main import config_values_main from primaite.common.config_values_main import config_values_main
from stable_baselines3 import PPO from stable_baselines3 import PPO
from stable_baselines3.ppo import MlpPolicy as PPOMlp from stable_baselines3.ppo import MlpPolicy as PPOMlp
@@ -271,9 +271,9 @@ except Exception as e:
# - new observation space # - new observation space
transaction_list = [] transaction_list = []
# Create the PRIMAITE environment # Create the Primaite environment
try: try:
env = PRIMAITE(config_values, transaction_list) env = Primaite(config_values, transaction_list)
logging.info("PrimAITE environment created") logging.info("PrimAITE environment created")
except Exception as e: except Exception as e:
logging.error("Could not create PrimAITE environment") logging.error("Could not create PrimAITE environment")

View File

@@ -3,7 +3,7 @@
A class that implements the access control list implementation for the network A class that implements the access control list implementation for the network
""" """
from acl.acl_rule import ACLRule from primaite.acl.acl_rule import ACLRule
class AccessControlList(): class AccessControlList():
""" """

View File

@@ -3,7 +3,7 @@
The Service class The Service class
""" """
from common.enums import SOFTWARE_STATE from primaite.common.enums import SOFTWARE_STATE
class Service(object): class Service(object):
""" """

View File

@@ -7,7 +7,7 @@
# "GENERIC" # "GENERIC"
agentIdentifier: STABLE_BASELINES3_A2C agentIdentifier: STABLE_BASELINES3_A2C
# Number of episodes to run per session # Number of episodes to run per session
numEpisodes: 10 numEpisodes: 10000
# Time delay between steps (for generic agents) # Time delay between steps (for generic agents)
timeDelay: 10 timeDelay: 10
# Filename of the scenario / laydown # Filename of the scenario / laydown

View File

@@ -1,6 +1,6 @@
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence. # Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
""" """
Main environment module containing the PRIMmary AI Training Evironment (PRIMAITE) class Main environment module containing the PRIMmary AI Training Evironment (Primaite) class
""" """
import numpy as np import numpy as np
@@ -15,24 +15,24 @@ from gym import Env, spaces
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from datetime import datetime from datetime import datetime
from common.enums import * from primaite.common.enums import *
from links.link import Link from primaite.links.link import Link
from pol.ier import IER from primaite.pol.ier import IER
from nodes.node_state_instruction_green import NodeStateInstructionGreen from primaite.nodes.node_state_instruction_green import NodeStateInstructionGreen
from nodes.node_state_instruction_red import NodeStateInstructionRed from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed
from pol.green_pol import apply_iers, apply_node_pol from primaite.pol.green_pol import apply_iers, apply_node_pol
from pol.red_agent_pol import apply_red_agent_iers, apply_red_agent_node_pol from primaite.pol.red_agent_pol import apply_red_agent_iers, apply_red_agent_node_pol
from nodes.active_node import ActiveNode from primaite.nodes.active_node import ActiveNode
from nodes.passive_node import PassiveNode from primaite.nodes.passive_node import PassiveNode
from nodes.service_node import ServiceNode from primaite.nodes.service_node import ServiceNode
from common.service import Service from primaite.common.service import Service
from acl.access_control_list import AccessControlList from primaite.acl.access_control_list import AccessControlList
from environment.reward import calculate_reward_function from primaite.environment.reward import calculate_reward_function
from transactions.transaction import Transaction from primaite.transactions.transaction import Transaction
class PRIMAITE(Env): class Primaite(Env):
""" """
PRIMmary AI Training Evironment (PRIMAITE) class PRIMmary AI Training Evironment (Primaite) class
""" """
# Observation / Action Space contants # Observation / Action Space contants
@@ -55,7 +55,7 @@ class PRIMAITE(Env):
_agent_identifier: Identifier for the agent _agent_identifier: Identifier for the agent
""" """
super(PRIMAITE, self).__init__() super(Primaite, self).__init__()
# Take a copy of the config values # Take a copy of the config values
self.config_values = _config_values self.config_values = _config_values

View File

@@ -3,9 +3,9 @@
Implements reward function Implements reward function
""" """
from common.enums import * from primaite.common.enums import *
from nodes.active_node import ActiveNode from primaite.nodes.active_node import ActiveNode
from nodes.service_node import ServiceNode from primaite.nodes.service_node import ServiceNode
def calculate_reward_function(initial_nodes, final_nodes, reference_nodes, green_iers, red_iers, step_count, config_values): def calculate_reward_function(initial_nodes, final_nodes, reference_nodes, green_iers, red_iers, step_count, config_values):
""" """

View File

@@ -3,8 +3,8 @@
The link class The link class
""" """
from common.protocol import Protocol from primaite.common.protocol import Protocol
from common.enums import * from primaite.common.enums import *
class Link(object): class Link(object):
""" """

View File

@@ -3,8 +3,8 @@
An Active Node (i.e. not an actuator) An Active Node (i.e. not an actuator)
""" """
from nodes.node import Node from primaite.nodes.node import Node
from common.enums import * from primaite.common.enums import *
class ActiveNode(Node): class ActiveNode(Node):
""" """

View File

@@ -3,7 +3,7 @@
The base Node class The base Node class
""" """
from common.enums import * from primaite.common.enums import *
class Node: class Node:
""" """

View File

@@ -3,7 +3,7 @@
The Passive Node class (i.e. an actuator) The Passive Node class (i.e. an actuator)
""" """
from nodes.node import Node from primaite.nodes.node import Node
class PassiveNode(Node): class PassiveNode(Node):
""" """

View File

@@ -3,8 +3,8 @@
A Service Node (i.e. not an actuator) A Service Node (i.e. not an actuator)
""" """
from nodes.active_node import ActiveNode from primaite.nodes.active_node import ActiveNode
from common.enums import * from primaite.common.enums import *
class ServiceNode(ActiveNode): class ServiceNode(ActiveNode):
""" """

View File

@@ -5,9 +5,9 @@ Implements Pattern of Life on the network (nodes and links)
from networkx import shortest_path from networkx import shortest_path
from common.enums import * from primaite.common.enums import *
from nodes.active_node import ActiveNode from primaite.nodes.active_node import ActiveNode
from nodes.service_node import ServiceNode from primaite.nodes.service_node import ServiceNode
_VERBOSE = False _VERBOSE = False

View File

@@ -5,9 +5,9 @@ Implements Pattern of Life on the network (nodes and links) resulting from the r
from networkx import shortest_path from networkx import shortest_path
from common.enums import * from primaite.common.enums import *
from nodes.active_node import ActiveNode from primaite.nodes.active_node import ActiveNode
from nodes.service_node import ServiceNode from primaite.nodes.service_node import ServiceNode
_VERBOSE = False _VERBOSE = False

View File

@@ -9,7 +9,7 @@ import os.path
from datetime import datetime from datetime import datetime
from transactions.transaction import Transaction from primaite.transactions.transaction import Transaction
def turn_action_space_to_array(_action_space): def turn_action_space_to_array(_action_space):
""" """

0
tests/__init__.py Normal file
View File

View File

@@ -4,8 +4,8 @@
Used to tes the ACL functions Used to tes the ACL functions
""" """
from acl.acl_rule import ACLRule from primaite.acl.acl_rule import ACLRule
from acl.access_control_list import AccessControlList from primaite.acl.access_control_list import AccessControlList
def test_acl_address_match_1(): def test_acl_address_match_1():
""" """

0
tests/test_reward.py Normal file
View File