Commit Graph

236 Commits

Author SHA1 Message Date
Marek Wolan
677d12b550 Merged PR 106: Resolve TODOs about documenting functions
## Summary
- Added type hints and docstrings to functions imported from ADSP.
- Imported `get_relevant_rules` which was referenced but didn't exist.
- Removed duplicated function definitions in `agents.utils`

## Test process
The changes in this PR are almost exclusively cosmetic. I can confirm that after adding/removing functions, the unit tests passed fine. I was also able to run the Hardcoded node and ACL agents without problems.

## 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

Related work items: #1575
2023-07-07 15:10:44 +00:00
Czar Echavez
036e0fe342 Merged PR 89: #1386 Enable a repeatable/deterministic baseline test
## Summary
- Added the fix from #1535 with minor changes to make sure that the `primaite_env.step()` function can properly parse the action
- added the config deterministic and seed to training config
- added the deterministic and seed to the Training config class, with defaults `False` and `None` respectively
- minor fix to `primaite_env.close()` function so that it now works

## Test process
Added e2e tests for generic, ppo and a2c which evaluates a trained agent twice to make sure that the seeding and deterministic action works

## 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

#1386: added the ability to set deterministic and seeding RNG when training and evaluating + the fix provided in #1535

Related work items: #1386, #1535
2023-07-07 09:22:47 +00:00
Czar Echavez
04e52453b1 Merge branch 'dev' into feature/1386-enable-a-repeatable-or-deterministic-baseline-test 2023-07-06 22:22:37 +01:00
Christopher McCarthy
207601b81f Merged PR 109: Auto save agent at end of training
## Summary
* Made RLlib and SB3 agents save at the end of each learning session by default using a common file naming format. Also now agents only checkpoint every n and not on the final episode.

## Test process
*Tests saved agent file in the test_primaite_session test.

## 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
- [ ] 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: #1593
2023-07-06 16:29:48 +00:00
Marek Wolan
3a75ed8ccc Merged PR 108: Divide default rewards by 10000
## Summary
As per the discussion this morning, this PR reimplements changes that were made by ADSP to make the default rewards smaller. This also adds type hints rewards as floats.

## Test process
I checked that sessions are able to run and that they report values similar to what we are used to but smaller by a factor of 10000. I did not change the reward values in the integration test configs, and the tests still pass.

## 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: #889, #1586
2023-07-06 15:17:47 +00:00
Chris McCarthy
c9f4741655 #1593 - Ran pre-commit hook 2023-07-06 14:18:49 +01:00
Chris McCarthy
82d7c168fe #1593 - Check that agent saved file exists 2023-07-06 14:13:02 +01:00
Chris McCarthy
159d47fd6c #1963 - Made RLlib and SB3 agents save at the end of each learning session by default using a common file naming format. Also now agents only checkpoint every n and not on the final episode 2023-07-06 13:56:12 +01:00
Czar Echavez
46b44f9e23 #1386: remove redundant config files + test fixtures + fixing deterministic and seed config description in documentation to avoid misunderstandings 2023-07-06 13:27:44 +01:00
Marek Wolan
3b91a99070 Updated rewards type description in docs 2023-07-06 12:56:24 +01:00
Marek Wolan
c5d7d55747 Change reward to float and divide by 10000 2023-07-06 12:52:14 +01:00
Czar Echavez
99f1f7cfc1 #1386: remove setting of global seed + running pre-commit checks 2023-07-06 12:10:26 +01:00
Chris McCarthy
3438ce7e09 #1386 - Updated tests in test_seeding_and_deterministic_session.py to use TempPrimaiteSession.
- Added test_seeded_learning test and test_deterministic_evaluation test.
- Passed config values seed and deterministic to ppo agent
- Dropped deterministic override in evaluate functions
- TempPrimaiteSession now writes files to a UUID folder rather than datetime
- Added seed to Ray RLlib agent setup in rllib.py
- Added seed to SB3 agent setup in sb3.py
2023-07-06 11:35:44 +01:00
Marek Wolan
e174db5d9e Rescaled default rewards by a factor of 1/10000 2023-07-06 10:51:34 +01:00
Marek Wolan
87bdaa1ec3 Updated documentation 2023-07-06 10:34:27 +01:00
Marek Wolan
c38dda34b9 Removed duplicated function definitions 2023-07-06 10:23:14 +01:00
Chris McCarthy
8faf9d70a0 temp 2023-07-06 10:07:54 +01:00
Marek Wolan
b426d5802e Updated docstrings 2023-07-05 16:46:23 +01:00
Marek Wolan
5c167293e3 Add docstrings and type hints. 2023-07-05 16:19:43 +01:00
Marek Wolan
0ae7158859 Merge branch 'bugfix/1587-hardcoded-agent' into feature/1575-docstring-param-desc 2023-07-05 15:22:13 +01:00
Czar Echavez
713225b432 #1386: remove unneeded configs + setting the seed globally + temp test 2023-07-05 15:02:41 +01:00
Marek Wolan
7482aead76 typo 2023-07-05 14:50:03 +01:00
Marek Wolan
171b5cb58e Imported ADSP function for ACL 2023-07-05 14:10:52 +01:00
Marek Wolan
b3d4eb4ec0 Changed hardcoded agent helper for new obs space 2023-07-05 13:58:46 +01:00
Czar Echavez
075b11aeca #1386: fix saving of agent 2023-07-05 11:41:18 +01:00
Marek Wolan
3ced1a1913 Update some param descriptions for hardcoded agent 2023-07-05 09:54:50 +01:00
Czar Echavez
9001510fe7 #1386: fix bug with agent zip file not being saved after run 2023-07-04 16:30:31 +01:00
Czar Echavez
410afc1d40 Merge branch 'dev' into feature/1386-enable-a-repeatable-or-deterministic-baseline-test 2023-07-04 09:41:07 +01:00
Christopher McCarthy
e199dc52c0 Merged PR 101: Integrate ADSP RLlib and use PrimaiteSession for running between agent frameworks
## Summary
* Brought over the RLlib, hardcoded agents, and simple agents from ADSP 1.1.0. This opened a can of worms... ADSP got their stuff working in notebooks (***_stares at data scientists!_** 😂) but hadn't integrated it into the PrimAITE package or made the other PrimAITE functionality work with it.
* RLlib agents have been fully integrated with the wider PrimAITE package. This was done by:
  * The creation of an `AgentSessionABC` and `HardCodedAgentSessionABC` classes.
  * `SB3Agent` and `RLlibAgent` classes then inherited from `AgentSessionABC`.
  * The ADSP hardcoded agents were integrated into subclasses of `HardCodedAgentSessionABC`.
  * The random and dummy agents were also integrated into subclasses of `HardCodedagentSessionABC`.
  * A set of session output directories were created and managed by the agent session to enable consistent storage of session outputs in a common format regardless of the agent type.
  * The main config was rafactored so that it had
    * **agent_framework** - To identify whether SB3, RLlib, or Custom.
    * **agent_identifier** - To identify whether PPO, A2C, hardcoded, random, or dummy.
    *  **deep_learning_framework** - To identify which framework to use for RLlib.
* Transactions have been overhauled to simplify the process. It also means that they're written in real time so they're not lost if the agent crashes.
* Tests completely overhauled to use `PrimaiteSession`, or at least a test subclass, `TempPrimaiteSession`. It's temp because it uses temp directory rather than main primaite session directory, and it cleans up after itself.
* All the crap removed from `main.py` and made it so that it just runs `PrimaiteSession`.

Now this is where I went off on a tangent...
* CLI added to just make my life and everyone else's life easier.
* Primaite app config added to hold things like logging format, levels etc.
* A `primaite.data_viz.session_plots` module added so that the average reward per episode for each session is plotted and saves for each session (this helped while we were testing and bug fixing).

## Test process
* All tests use `TempPrimaiteSession`, which uses `PrimaiteSession`.
* I still need to write a tests that runs the RLlib, hardcoded, and random/dummy agents. I'll do that now while this is being reviewed.

## Still to do
* Update docs. I'm getting this PR up now so we can get it in to make use of the features. I'll get the docs updated today either on this branch or another branch (depending on how long this review takes).

## 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
- [ ] 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: #917, #1563
2023-07-04 08:08:31 +00:00
Chris McCarthy
34b294f89a #917 - Reinstalled the pre-commit hook 2023-07-03 20:40:38 +01:00
Chris McCarthy
410d5abe12 #917 - Synced with dev and integrated the new observation space 2023-07-03 20:36:21 +01:00
Chris McCarthy
820f436f8e Merge remote-tracking branch 'origin/dev' into feature/917_Integrate_with_RLLib
# Conflicts:
#	src/primaite/config/_package_data/training/training_config_main.yaml
#	src/primaite/environment/primaite_env.py
#	src/primaite/main.py
#	src/primaite/transactions/transaction.py
#	src/primaite/transactions/transactions_to_file.py
2023-07-03 19:51:52 +01:00
Chris McCarthy
7816e94f83 #917 - Synced with dev (at the point of random red agent) 2023-07-03 17:25:21 +01:00
Chris McCarthy
dffa612ec8 Merge remote-tracking branch 'origin/feature/917_Integrate_with_RLLib' into feature/917_Integrate_with_RLLib 2023-07-03 17:12:03 +01:00
Marek Wolan
4b5cf12aa3 Merged PR 103: Change build pipeline to enable installing from wheel on windows
## Summary
Just splits the install primaite step into two depending if agent is using windows or not.

## Test process
Ran a build successfully.

## 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
2023-07-03 16:10:09 +00:00
Marek Wolan
7ddedfcc57 Updated azure-ci-build-pipeline.yaml 2023-07-03 16:02:59 +00:00
Czar Echavez
a883e45bbf Merge branch 'dev' into feature/1386-enable-a-repeatable-or-deterministic-baseline-test 2023-07-03 16:56:44 +01:00
Marek Wolan
8ab936fcdc Merged PR 100: Flatten observation spaces and improve transactions for observations
## Summary
*Replace this text with an explanation of what the changes are and how you implemented them. Can this impact any other parts of the codebase that we should keep in mind?*

## Test process
I ran some training sessions to ensure that the outputted transaction list has the correct data and headers. I was also able to verify that the agent is able to train with observation spaces containing multiple components.

I trained an agent on laydown 3 with NODE_LINK_TABLE both as normal and flattened spaces and the agent learned in both instances.
![image.png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/100/attachments/image.png)  ![image (2).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/100/attachments/image%20%282%29.png)
## 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: #1558
2023-07-03 15:54:00 +00:00
Chris McCarthy
d2764d53cc Merge remote-tracking branch 'origin/dev' into feature/917_Integrate_with_RLLib
# Conflicts:
#	src/primaite/config/_package_data/training/training_config_main.yaml
#	src/primaite/environment/primaite_env.py
2023-07-03 15:07:09 +01:00
Marek Wolan
12c18adeb1 Merge remote-tracking branch 'origin/dev' into feature/1558-flatten-spaces 2023-07-03 15:03:10 +01:00
Marek Wolan
178bd4dc7f Merge branch 'dev' into feature/1558-flatten-spaces 2023-07-03 15:01:56 +01:00
Marek Wolan
f47dd8bf61 Updated azure-ci-build-pipeline.yaml 2023-07-03 13:36:33 +00:00
Czar Echavez
dc4c2c8854 Merged PR 102: 1522 Red Agent random behaviour
## Summary
Ported over ADSP changes regarding the randomised red agent.
Red agent currently only works on laydown configs which contain links.

Each episode generates random red agent instructions

## Test process
Written a test that ensures that the random red agent produces random red agent instructions

| Random red agent | Laydown                | Agent Identifier | Run 1                                                                              | Run 2                                                                              | Run 3                                                                              |
|------------------|------------------------|------------------|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| NONE             | Very Basic (Laydown 3) | A2C              | ![image (4).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%284%29.png)  | ![image (8).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%288%29.png)  | ![image (9).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%289%29.png)  |
| RANDOM           | Very Basic (Laydown 3) | A2C              | ![image (5).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%285%29.png)  | ![image (6).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%286%29.png)  | ![image (7).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%287%29.png)  |
| NONE             | Very Basic (Laydown 3) | PPO              | ![image (10).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%2810%29.png) | ![image (11).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%2811%29.png) | ![image (12).png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/102/attachments/image%20%2812%29.png) |
| RANDOM           | Very Basic (Laydown 3) | PPO              ...
2023-07-03 13:09:32 +00:00
Marek Wolan
8101f49a21 Updated azure-ci-build-pipeline.yaml 2023-07-03 12:44:01 +00:00
Marek Wolan
63a4c1119b Updated azure-ci-build-pipeline.yaml 2023-07-03 12:40:02 +00:00
Marek Wolan
94ca28a85f Add windows build option 2023-07-03 12:37:08 +00:00
Czar Echavez
cb9d40579f #1522: create_random_red_agent -> _create_random_red_agent + converting NodeStateInstructionRed into a dataclass 2023-07-03 13:36:14 +01:00
Czar Echavez
0943e9511b #1522: refactor red_agent_identifier -> random_red_agent so that it is a boolean + documentation 2023-07-03 12:18:58 +01:00
Chris McCarthy
c3ec33e4df #917 - Added Windows and MacOS to build pipeline. Updated so that runs only Python 3.8 and 3.10 (middle version not required) 2023-07-03 12:03:36 +01:00
Chris McCarthy
123ec8343c Merge remote-tracking branch 'origin/dev' into feature/917_Integrate_with_RLLib
# Conflicts:
#	tests/test_reward.py
2023-07-03 11:59:16 +01:00