Skip to content

Commit 0295fb8

Browse files
Dmytro Korenkevychfacebook-github-bot
Dmytro Korenkevych
authored andcommitted
WIP documentation generation via gh actions (#107)
Summary: Pull Request resolved: #107 Differential Revision: D67157339
1 parent cafb382 commit 0295fb8

File tree

6 files changed

+58
-29
lines changed

6 files changed

+58
-29
lines changed

.github/workflows/CI.yml

+43-15
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,60 @@ jobs:
55
runs-on: ${{ matrix.os }}
66
strategy:
77
matrix:
8-
os: [ubuntu-latest, macos-latest, windows-latest]
8+
os: [ubuntu-latest]
99
env:
1010
OS: ${{ matrix.os }}
11-
PYTHON: '3.9'
11+
PYTHON: "3.10"
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Setup Python
1515
uses: actions/setup-python@v4
1616
with:
17-
python-version: 3.9
17+
python-version: "3.10"
1818
- name: Install dependencies
1919
run: |
20+
pip install pdoc3
2021
pip install pytest
2122
pip install pytest-cov
2223
pip install -e .
23-
- name: Generate coverage report
24+
- name: Update documentation
2425
run: |
25-
pytest --cov=./ --cov-report=xml
26-
- name: Upload coverage to Codecov
27-
if: success() || failure()
28-
uses: codecov/codecov-action@v4
26+
pdoc --html pearl.neural_networks.sequential_decision_making --html-dir html --force
27+
- name: Upload docs artifacts
28+
uses: actions/upload-artifact@v4
2929
with:
30-
env_vars: OS,PYTHON
31-
file: ./coverage.xml
32-
flags: unittests
33-
name: codecov-umbrella
34-
token: ${{ secrets.CODECOV_TOKEN }}
35-
slug: facebookresearch/Pearl
36-
verbose: true
30+
# Name of the artifact to upload.
31+
# Optional. Default is 'artifact'
32+
name: artifact
33+
34+
# A file, directory or wildcard pattern that describes what to upload
35+
# Required.
36+
path: html/
37+
38+
# The desired behavior if no files are found using the provided path.
39+
# Available Options:
40+
# warn: Output a warning but do not fail the action
41+
# error: Fail the action with an error message
42+
# ignore: Do not output any warnings or errors, the action does not fail
43+
# Optional. Default is 'warn'
44+
if-no-files-found: warn
45+
46+
# If true, an artifact with a matching name will be deleted before a new one is uploaded.
47+
# If false, the action will fail if an artifact for the given name already exists.
48+
# Does not fail if the artifact does not exist.
49+
# Optional. Default is 'false'
50+
overwrite: true
51+
# - name: Generate coverage report
52+
# run: |
53+
# pytest --cov=./ --cov-report=xml
54+
# - name: Upload coverage to Codecov
55+
# if: success() || failure()
56+
# uses: codecov/codecov-action@v4
57+
# with:
58+
# env_vars: OS,PYTHON
59+
# file: ./coverage.xml
60+
# flags: unittests
61+
# name: codecov-umbrella
62+
# token: ${{ secrets.CODECOV_TOKEN }}
63+
# slug: facebookresearch/Pearl
64+
# verbose: true

pearl/api/action_result.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class ActionResult:
2323
reward: Reward
2424
terminated: bool
2525
truncated: bool
26-
info: dict[str, Any] | None = None
27-
cost: float | None = None
28-
available_action_space: ActionSpace | None = None
26+
info: Optional[dict[str, Any]] = None
27+
cost: Optional[float] = None
28+
available_action_space: Optional[ActionSpace] = None
2929

3030
@property
3131
def done(self) -> bool:

pearl/history_summarization_modules/history_summarization_module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HistorySummarizationModule(ABC, nn.Module):
2626

2727
@abstractmethod
2828
def summarize_history(
29-
self, observation: Observation, action: Action | None
29+
self, observation: Observation, action: Optional[Action]
3030
) -> SubjectiveState:
3131
pass
3232

pearl/neural_networks/common/epistemic_neural_networks.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(
3737
super().__init__()
3838

3939
@abstractmethod
40-
def forward(self, x: Tensor, z: Tensor) -> Tensor:
40+
def forward(self, x: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
4141
"""
4242
Input:
4343
x: Feature vector of state action pairs
@@ -71,7 +71,7 @@ def __init__(
7171
self.prior_net: nn.Module = mlp_block(input_dim, hidden_dims, output_dim).eval()
7272
self.scale = scale
7373

74-
def forward(self, x: Tensor) -> Tensor:
74+
def forward(self, x: torch.Tensor) -> torch.Tensor:
7575
"""
7676
Input:
7777
x: Tensor. Feature vector input
@@ -116,7 +116,7 @@ def __init__(
116116

117117
self._resample_epistemic_index()
118118

119-
def forward(self, x: Tensor, z: Tensor, persistent: bool = False) -> Tensor:
119+
def forward(self, x: torch.Tensor, z: torch.Tensor, persistent: bool = False) -> torch.Tensor:
120120
"""
121121
Input:
122122
x: Feature vector of state action pairs
@@ -176,14 +176,14 @@ def generate_params_buffers(self) -> None:
176176
self.params, self.buffers = torch.func.stack_module_state(self.models)
177177

178178
def call_single_model(
179-
self, params: dict[str, Any], buffers: dict[str, Any], data: Tensor
180-
) -> Tensor:
179+
self, params: dict[str, Any], buffers: dict[str, Any], data: torch.Tensor
180+
) -> torch.Tensor:
181181
"""
182182
Method for parallelizing priornet forward passes with torch.vmap.
183183
"""
184184
return torch.func.functional_call(self.base_model, (params, buffers), (data,))
185185

186-
def forward(self, x: Tensor, z: Tensor) -> Tensor:
186+
def forward(self, x: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
187187
"""
188188
Perform forward pass on the priornet ensemble and weight by epistemic index
189189
x and z are assumed to already be formatted.
@@ -235,7 +235,7 @@ def __init__(
235235
self.input_dim, self.prior_hiddens, self.output_dim, self.index_dim
236236
)
237237

238-
def format_xz(self, x: Tensor, z: Tensor) -> Tensor:
238+
def format_xz(self, x: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
239239
"""
240240
Take cartesian product of x and z and concatenate for forward pass.
241241
Input:
@@ -251,7 +251,7 @@ def format_xz(self, x: Tensor, z: Tensor) -> Tensor:
251251
xz = torch.cat([x_expanded, z_expanded], dim=-1)
252252
return xz.view(batch_size * num_indices, d + self.index_dim)
253253

254-
def forward(self, x: Tensor, z: Tensor, persistent: bool = False) -> Tensor:
254+
def forward(self, x: torch.Tensor, z: torch.Tensor, persistent: bool = False) -> torch.Tensor:
255255
"""
256256
Input:
257257
x: Feature vector containing item and user embeddings and interactions

pearl/neural_networks/sequential_decision_making/actor_networks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def forward(self, x: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
421421
return mean, log_std
422422

423423
def sample_action(
424-
self, state_batch: Tensor, get_log_prob: bool = False
424+
self, state_batch: torch.Tensor, get_log_prob: bool = False
425425
) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
426426
"""
427427
Sample an action from the actor network.

pearl/neural_networks/sequential_decision_making/twin_critic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def __init__(
3434
action_dim: int,
3535
hidden_dims: Iterable[int],
3636
init_fn: Callable[[nn.Module], None],
37-
network_type: type[QValueNetwork] = VanillaQValueNetwork,
37+
#network_type: type[QValueNetwork] = VanillaQValueNetwork,
38+
network_type: VanillaQValueNetwork = VanillaQValueNetwork,
3839
output_dim: int = 1,
3940
) -> None:
4041
super().__init__()

0 commit comments

Comments
 (0)