Commit Graph

448 Commits

Author SHA1 Message Date
Chris McCarthy
7fe5df7fc4 Bumped version to 2.0.0 2023-07-26 14:38:57 +01:00
Christopher McCarthy
8bf1440f9b Merged PR 139: Re-run the benchmarks for v2.0.0rc1 and v2.0.0rc2 using the same config file....
## Summary
Re-run the benchmarks for v2.0.0rc1 and v2.0.0rc2 using the same config file. As expected, the versions perform almost identically as there's no real logic changes that would affect the agent between the two release candidates

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

Related work items: #1574
2023-07-25 09:33:32 +00:00
Chris McCarthy
e9b52a69b7 Merge remote-tracking branch 'origin/dev' into release/2.0.0rc1
# Conflicts:
#	.gitignore
#	benchmark/results/PrimAITE Versions Learning Benchmark.png
#	benchmark/results/v2.0.0rc1/PrimAITE v2.0.0rc1 Learning Benchmark.pdf
#	benchmark/results/v2.0.0rc1/PrimAITE v2.0.0rc1 Learning Benchmark.png
#	benchmark/results/v2.0.0rc1/v2.0.0rc1_benchmark_metadata.json
2023-07-24 22:50:34 +01:00
Chris McCarthy
4f16105b67 RE-ran the benchmarks for v2.0.0rc1 and v2.0.0rc2 using the same config file. As expected, the versions perform almost identically as there's no real logic changes that would affect the agent between the two release candidates 2023-07-24 22:43:22 +01:00
Christopher McCarthy
7e0f55cdb8 Merged PR 137: #1650 - Turned on the test. Also updated some references to the old primaite...
## Summary
- Turned on the test. Also updated some references to the old primaite paths. Finally, pushed the deployment status classifier to Development Status :: 5 - Production/Stable

## Test process
Yes, turned on the test.

## Checklist
- [ ] This PR is linked to a **work item**
- [ ] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [ ] I have run **pre-commit** checks for code style

#1650 - Turned on the test. Also updated some references to the old primaite paths. Finally, pushed the deployment status classifier to Development Status :: 5 - Production/Stable

Related work items: #1650
2023-07-24 11:11:17 +00:00
Chris McCarthy
31955c0c84 #1650 - Removed the commented out pytest.mark.skip statement now that the test does work. 2023-07-24 09:20:36 +01:00
Chris McCarthy
ef6585a298 #1650 - Turned on the test. Also updated some references to the old primaite paths. Finally, pushed the deployment status classifier to Development Status :: 5 - Production/Stable 2023-07-21 16:49:17 +01:00
Christopher McCarthy
5d9dd7a2d9 Merged PR 135: #1648 - Updated file headers
## Summary
 - Updated file header from 'Crown Owned Copyright (C) Dstl 2023. DEFCON 703. Shared in confidence.' to '© Crown-owned copyright 2023, Defence Science and Technology Laboratory UK'

## Checklist
- [ ] This PR is linked to a **work item**
- [ ] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [ ] I have run **pre-commit** checks for code style

#1648 - Updated file header from 'Crown Owned Copyright (C) Dstl 2023. DEFCON 703. Shared in confidence.' to '© Crown-owned copyright 2023, Defence Science and Technology Laboratory UK'

Related work items: #1648
2023-07-21 14:08:09 +00:00
Chris McCarthy
a39541623a #1648 - Reverted benchmark sessions and episodes numbers 2023-07-21 15:07:21 +01:00
Chris McCarthy
63297ef0ed #1648 - Added header to benchmark files 2023-07-21 15:06:05 +01:00
Chris McCarthy
4527b38aa6 #1648 - Reverted the benchmark files 2023-07-21 15:01:51 +01:00
Chris McCarthy
050ca68907 #1648 - Updated file header from 'Crown Owned Copyright (C) Dstl 2023. DEFCON 703. Shared in confidence.' to '© Crown-owned copyright 2023, Defence Science and Technology Laboratory UK' 2023-07-21 14:54:09 +01:00
Christopher McCarthy
cda0a28c03 Merged PR 134: PrimAITE app and user dirs are version specific
## Summary
- Added _PrimaitePaths class that manages all the primaite locations using PlayformDirs. This class now creates new primaite locations for each version of primaite.
- Rolled the _PrimaitePaths class out throughout the code base.
- Updated the docs to reference the new version paths.
- Updated the author from qinetiq to dstl
- Bumped version number to 2.0.0rc2

## Test process
- Manual checks. Tough to test the install paths.

## Checklist
- [ ] This PR is linked to a **work item**
- [ ] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [ ] I have run **pre-commit** checks for code style

Related work items: #1647
2023-07-21 13:50:56 +00:00
Chris McCarthy
b8ca5f1dca Merge branch 'dev' into feature/1647_Append_version_number_to_the_primaite_root_dir 2023-07-21 14:01:45 +01:00
Chris McCarthy
196d8855c3 #1647 - Added _PrimaitePaths class that manages all the primaite locations using PlayformDirs. This class now creates new primaite locations for each version of primaite.
- Rolled the _PrimaitePaths class out throughout the code base.
- Updated the docs to reference the new version paths.
- Updated the author from qinetiq to dstl
- Bumped version number to 2.0.0rc2
2023-07-21 14:00:50 +01:00
Czar Echavez
e1a396981a Merged PR 130: #1595: load session double run
## Summary
- Fixed the bug where session gets run twice when loading a session via CLI
- Added a test for the CLI run - xskipped while the bugfix for load session acting odd is tbd
- Fixed a minor bug in PrimAITE session where session_path is overwritten

## Test process
Added a new test for CLI, but xskipped while a different bug is tbd

Ran it locally and no longer runs another session after the loaded session
```
(venv) PS D:\Projects\ARCD\PrimAITE\PrimAITE> primaite session --load [REDACTED for security]\primaite\sessions\2023-07-20\2023-07-20_15-01-11
2023-07-20 15:04:21,320: Using: AgentFramework.SB3, AgentIdentifier.PPO, ActionType.NODE, observation_space=NODE_LINK_TABLE, Training: 5 episodes @ 256 stepsEvaluation: 5 episodes @ 256 steps
2023-07-20 15:04:21,335: Environment configuration loaded
Environment configuration loaded
2023-07-20 15:04:21,775: Welcome to the Primary-level AI Training Environment (PrimAITE) (version: 2.0.0rc1)
2023-07-20 15:04:21,775: The output directory for this session is: C:\Users\czar.echavez\primaite\sessions\2023-07-20\2023-07-20_15-04-21
2023-07-20 15:04:21,779: Beginning learning for 10 episodes @ 256 time steps...
2023-07-20 15:04:22,379: Episode: 1, Average Reward: -0.0020839843750000003
2023-07-20 15:04:23,137: Episode: 2, Average Reward: -0.0021933593750000004
2023-07-20 15:04:23,831: Episode: 3, Average Reward: -0.0022617187500000003
2023-07-20 15:04:24,486: Episode: 4, Average Reward: -0.002373046874999999
2023-07-20 15:04:25,125: Episode: 5, Average Reward: -0.0018066406250000014
2023-07-20 15:04:25,791: Episode: 6, Average Reward: -0.0017597656250000013
2023-07-20 15:04:26,415: Episode: 7, Average Reward: -0.0018437500000000014
2023-07-20 15:04:27,053: Episode: 8, Average Reward: -0.0019101562500000015
2023-07-20 15:04:27,715: Episode: 9, Average Reward: -0.0016777343750000013
2023-07-20 15:04:28,359: Episode: 10, Average Reward: -0.0015976562500000012
2023-07-20 15:04:28,550: Finished learning
2023-07-20 15:04:30,851: Beginning deterministic evaluation for 5 episodes @ 256 time steps...
2023-07-20 15:04:31,243: Episode: 1, Average Reward: -0.0018515625000000014
2023-07-20 15:04:31,663: Episode: 2, Average Reward: -0.0018515625000000014
2023-07-20 15:04:32,112: Episode: 3, Average Reward: -0.0018515625000000014
2023-07-20 15:04:32,505: Episode: 4, Average Reward: -0.0018515625000000014
2023-07-20 15:04:32,904: Episode: 5, Average Reward: -0.0018515625000000014
2023-07-20 15:04:32,998: Finished evaluation

```

Also fixed the xskipped tests, since the double running seems to have caused the issue of rewards not matching.

Added a test that runs the PrimAITE in CLI

## Checklist
- [x] This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [x] I have written **tests** for any new functionality added with this PR
- [x] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

#1595:
- Fixed the...
2023-07-21 11:32:32 +00:00
Christopher McCarthy
10c8604159 Merged PR 132: #1594 - Managed to get the evaluation of rllib agents working. A test has bee...
## Summary
Managed to get the evaluation of rllib agents working. A test has been added to test_primaite_session.py that now tests the full RLlib agent from end-to-end. I've also updated the tests in here to check that the mean reward per episode plot is created for both too. This will need a bit of a re-design further down the line, but for now, it works. Added a custom exception for RLlib eval only error.

Is this a hack? Yes. Does it work? Yes. we'll make this better later.

## Test process
Both a SB3 and Ray RLlib agent is tested now in the test_primaite_session.py module.

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

Related work items: #1594
2023-07-21 10:26:31 +00:00
Chris McCarthy
722fe97c84 #1594 - Added docstrings and fixed training type. Added a clean-up of the unpacked agent in eval dir. 2023-07-21 10:33:22 +01:00
Christopher McCarthy
e62bee3052 Merged PR 131: #1639 - Added CHANGELOG.md and backfilled it with v1.1.0 and v1.1.1 release n...
## Summary
Added changelog and backfilled with v1.1.0 and v1.1.0 release notes.

Check what's written against notes in: https://nscuk.sharepoint.com/:f:/r/sites/SSE32-ARCDTrainingEnvironments/Shared%20Documents/General/01%20PrimAITE/01.01%20Releases/Release%20Notes?csf=1&web=1&e=uwPsyM

## Test process
N/A

## Checklist
- [ ] This PR is linked to a **work item**
- [ ] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [ ] I have run **pre-commit** checks for code style

#1639 - Added CHANGELOG.md and backfilled it with v1.1.0 and v1.1.1 release notes.

Related work items: #1639
2023-07-21 09:28:28 +00:00
Czar Echavez
7999eb56a5 #1595: refactor variable name 2023-07-21 09:31:37 +01:00
Czar Echavez
21598fd792 #1595: possibly fixed the tests by fixing the bug 2023-07-21 09:17:38 +01:00
Chris McCarthy
df52236a7d #1594 - Managed to get the evaluation of rllib agents working. A test has been added to test_primaite_session.py that now tests the full RLlib agent from end-to-end. I;ve also updated the tests in here to check that the mean reward per episode plot is created for both too. This will need a bit of a re-design further down the line, but for now, it works. Added a custom exception for RLlib eval only error. 2023-07-20 19:58:48 +01:00
Chris McCarthy
470f52f35e #1639 - Reinstalled pre-commit hook 2023-07-20 18:45:02 +01:00
Chris McCarthy
5475155686 #1639 - Added CHANGELOG.md and backfilled it with v1.1.0 and v1.1.1 release notes. 2023-07-20 17:24:55 +01:00
Brian Kanyora
0a6078df65 Merged PR 129: feature/1641:Update config.rst
## Summary
Changed environment config to training config in config.rst as Chris requested.

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

feature/1641:
Changed environment config to training config

Related work items: #1641
2023-07-20 15:50:13 +00:00
Czar Echavez
fabbde9641 #1595:
- Fixed the bug where session gets run twice when loading a session via CLI
- Added a test for the CLI run - xskipped while the bugfix for load session acting odd is tbd
- Fixed a minor bug in PrimAITE session where session_path is overwritten
2023-07-20 16:21:30 +01:00
Brian Kanyora
69e7b23d2c feature/1641:
Changed environment config to training config
2023-07-20 16:09:57 +01:00
Sunil Samra
ae8afbdcdc Merged PR 128: #1640 - Update Sphinx Docs for 2.0.0 Release
## Summary
Added to docs as per @<Christopher McCarthy> changes - added prefixes to command line primaite session and explained primate session default no arguments command.

## Test process
*NA*

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

#1640 - Added --ldc and --tc prefixes and added small note about primaite session default run command

Related work items: #1640
2023-07-20 14:31:05 +00:00
SunilSamra
6ce816f2e1 #1640 - Added --ldc and --tc prefixes and added small note about primaite session default run command 2023-07-20 14:45:55 +01:00
Brian Kanyora
f840e924e3 Merged PR 125: feature/1637:Updating-UML-Diagram
## Summary
Updated the UML diagram using puml to help render a better output of the diagram.

## Checklist
- [x] This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [na] I have written **tests** for any new functionality added with this PR
- [na] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

feature/1637:
Updating the UML diagram using puml instead of mmd.

Related work items: #1637
2023-07-20 13:34:26 +00:00
Christopher McCarthy
3bbc7b8615 Merged PR 126: PrimAITE Benchmarking
## Summary
 - Added full benchmarking script that included plots and a LaTeX report. Ran the v2.0.0rc1 benchmark. Tidied a few other things up.

The code is a bit scrappy. But it's not released code. I will endeavour to tidy it up at a later date.

## Test process
Manually ran the script. This is the final report -> [PrimAITE v2.0.0rc1 Learning Benchmark.pdf](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/126/attachments/PrimAITE%20v2.0.0rc1%20Learning%20Benchmark.pdf)

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

Related work items: #1632
2023-07-20 12:58:54 +00:00
Marek Wolan
f6a9063484 Merged PR 127: Add license
## Summary
Add license file and reference it in the pyproject.toml

## Test process
Running `pip-licenses` shows:
```
 pre-commit                     2.20.0       MIT License
 primaite                       2.0.0rc1     MIT
 primaite                       2.0.0rc1     MIT
 prometheus-client              0.17.1       Apache Software License
 prompt-toolkit                 3.0.39       BSD License
```
## Checklist
- [x This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

Related work items: #1638
2023-07-20 11:16:05 +00:00
Brian Kanyora
90620e0c64 feature/1637:
Fixed the relationship between PrimIATE and Transaction.
2023-07-20 10:54:42 +01:00
Chris McCarthy
3731b2ba13 #1632 - Fixed output directory clear bug. Added gputil to dev deps. 2023-07-20 10:28:19 +01:00
Marek Wolan
dd9613853b Apply suggestions from code review 2023-07-20 09:21:35 +00:00
Chris McCarthy
f22681d6b4 #1632 - Added Python version to the System Information section in the report 2023-07-20 10:16:29 +01:00
Chris McCarthy
e9fc9a0d1a #1632 - Increased rolling window from 5 to 25 2023-07-20 10:06:44 +01:00
Marek Wolan
1e24ce7b9a Add license 2023-07-20 10:03:05 +01:00
Chris McCarthy
afbe2e1400 #1632 - Added full benchmarking script that included plots and a LaTeX report. Ran the v2.0.0rc1 benchmark. Tidied a few other things up. 2023-07-20 08:48:18 +01:00
Brian Kanyora
f8959a65e9 feature/1637:
Updating the UML diagram using puml instead of mmd.
2023-07-19 17:03:10 +01:00
Chris McCarthy
ba6f8f054b Merge branch 'dev' into feature/1632_Add_benchmarking_scripts 2023-07-18 13:24:15 +01:00
Christopher McCarthy
52a7185583 Merged PR 124: #1635 - Updated the session outputs details in primaite_session.rst
## Summary
- Updated the session outputs details in primaite_session.rst
- Fixed Logger typehint bugs
- Fixed typing issues in access_control_list.py

## Test process
Build the docs

![image.png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/124/attachments/image.png)

## Checklist
- [ ] This PR is linked to a **work item**
- [ ] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [ ] I have run **pre-commit** checks for code style

#1635 - Updated the session outputs details in primaite_session.rst

Related work items: #1635
2023-07-18 10:44:17 +00:00
Chris McCarthy
d730a206d8 #1635 - Fixed typing issues in access_control_list.py 2023-07-18 11:38:28 +01:00
Chris McCarthy
713aa279ec Merge branch 'dev' into feature/1635_Update_Primaite_Session_page_in_Docs
# Conflicts:
#	src/primaite/setup/old_installation_clean_up.py
#	src/primaite/setup/reset_example_configs.py
2023-07-18 11:36:31 +01:00
Chris McCarthy
e070b247b1 #1635 - Updated the session outputs details in primaite_session.rst
- Fixed Logger typehint bugs
2023-07-18 11:34:41 +01:00
Sunil Samra
a10a1d9267 Merged PR 120: Change Functionality of ACL Rules
## Summary
### ACL List
First change was I changed `access_control_list.py` from a `dict` to a `list` so it is now an ordered structure. This was done so I could implement the positions inside the `ACL` and `ANY` action spaces.

From this, some functions have changed such as `add_rule` and `remove_rule`, `is_blocked` and `get_relevant_rules`.

The ACL list is now a fixed size and on initialisation it is filled with `None` types. When a function calls `self.acl` the `implicit rule` (if there is one) is added after the last `ACLRule` object in the list. The remainder of the list (if there is left over space) is padded out with `None`.

As the agent adds rules, the `None` are replaced by `ACLRule` objects and the agent cannot overwrite an existing `ACLRule` with another, it can only write over `None` types.

### ACL Training Config Changes
Changes have been made to the `training_config_main.yaml`. There are 2 new items:

`implicit_acl_rule:` - Implicit ACL firewall rule at end of list to be default action (ALLOW or DENY)
`max_number_acl_rules:` - Total number of ACL rules allowed in the environment

In the `OBSERVATION_SPACE` area of the config, `ACCESS_CONTROL_LIST` can be selected

They have default values if none are specified so for the older configs - these values are in the `TrainingConfig` dataclass.

### ACL and ANY Action Spaces
I changed the ACL space from length of 6 to 7. I have included the `position` of where the agent wants to position the ACL Rule.

`position` = index in `self.acl` with bounds [0 to ...]

As a result, total possible actions have gone up.

### ACL Observation Space
In the observations.py I have made a new observation component: Access Control List.
It has the following mappings/meanings:

        [0, 1, 2] - Permission (0 = NA, 1 = DENY, 2 = ALLOW)
        [0, num nodes] - Source IP (0 = NA, 1 = any, then 2 -> x resolving to Node IDs)
        [0, num nodes] - Dest IP (0 = NA, 1 = any, then 2 -> x resolving to Node IDs)
        [0, num services] - Protocol (0 = NA, 1 = any, then 2 -> x resolving to protocol)
        [0, num ports] - Port (0 = NA, 1 = any, then 2 -> x resolving to port)
        [0, max acl rules - 1] - Position (0 = NA, 1 = first index, then 2 -> x index resolving to acl rule in acl list)

I created a new 0 meaning, which means NA and represents the None objects in the ACLList.

Also, there is no 'flatten' in the observation space components and this has been done in the observations.py now if there are multiple components.

## Test process
I have written tests in a new `TestAccessControlList` object in `test_observations.py`.

I ran a single test which was 1000 episodes, SB3/PPO, Config 5 and ACL Observation Space. I seemed to get some interesting results which may need investigating on Monday.

![Figure_1.png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/120/attachments/Figure_1.png)

## Checklist
- ...
2023-07-18 10:31:15 +00:00
Marek Wolan
9e3285350a Get tests working with new ACL changes 2023-07-18 11:16:39 +01:00
Marek Wolan
c5f612889e Merge remote-tracking branch 'origin/dev' into feature/901-change-functionality-acl-rules 2023-07-18 10:55:31 +01:00
Marek Wolan
9c6ee73b9e Merged PR 122: Typehint everything
## Summary
Added typehints to functions/methods, and class attributes.

## Test process
I used flake8-annotations and mypy to verify completeness and correctness. Mypy did throw up a very large number of errors and many of them point to some potential problems in the codebase. To elaborate, there are some places where there has been confusion as to whether objects should be strings, integers, or enums. Resolving this is out of scope of this PR but I will create more tickets with concrete examples.

## Checklist
- [x] This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

Related work items: #1623
2023-07-18 09:43:08 +00:00
Marek Wolan
a2ef4328dd Remove redundant 'if TYPE_CHECKING' statements 2023-07-18 10:21:06 +01:00