Skip to content

Commit

Permalink
Add testing for BeyondDFT workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Sep 18, 2024
1 parent 91dbb86 commit 07748d5
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ def resolve_all_outputs(self) -> list[Outputs]:
Returns:
list[Outputs]: A list of all the `Outputs` sections from the `tasks`.
"""
# Initial check
if not self.tasks:
return []

# Populate the list of outputs from the last element in `tasks`
all_outputs = []
for task in self.tasks:
if not task.outputs:
continue
all_outputs.append(task.outputs[-1])
return all_outputs

Expand Down
85 changes: 82 additions & 3 deletions tests/workflow/test_base_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from nomad_simulations.schema_packages.model_system import ModelSystem
from nomad_simulations.schema_packages.outputs import Outputs
from nomad_simulations.schema_packages.workflow import (
BeyondDFT,
BeyondDFTMethod,
BeyondDFTWorkflow,
SimulationWorkflow,
)

Expand Down Expand Up @@ -211,5 +211,84 @@ def test_resolve_beyonddft_method_ref(


class TestBeyondDFT:
def test_resolve_all_outputs(self):
assert True
@pytest.mark.parametrize(
'tasks, result',
[
# no task
(None, []),
# empty task
([Task()], []),
# task only contains inputs
(
[Task(inputs=[Link(name='Input Model System', section=ModelSystem())])],
[],
),
# one task with one output
(
[Task(outputs=[Link(name='Output Data 1', section=Outputs())])],
[Link(name='Output Data 1', section=Outputs())],
),
# one task with multiple outputs (only last is resolved)
(
[
Task(
outputs=[
Link(name='Output Data 1', section=Outputs()),
Link(name='Output Data 2', section=Outputs()),
]
)
],
[Link(name='Output Data 2', section=Outputs())],
),
# multiple task with one output each
(
[
Task(
outputs=[Link(name='Task 1:Output Data 1', section=Outputs())]
),
Task(
outputs=[Link(name='Task 2:Output Data 1', section=Outputs())]
),
],
[
Link(name='Task 1:Output Data 1', section=Outputs()),
Link(name='Task 2:Output Data 1', section=Outputs()),
],
),
# multiple task with two outputs each (only last is resolved)
(
[
Task(
outputs=[
Link(name='Task 1:Output Data 1', section=Outputs()),
Link(name='Task 1:Output Data 2', section=Outputs()),
]
),
Task(
outputs=[
Link(name='Task 2:Output Data 1', section=Outputs()),
Link(name='Task 2:Output Data 2', section=Outputs()),
]
),
],
[
Link(name='Task 1:Output Data 2', section=Outputs()),
Link(name='Task 2:Output Data 2', section=Outputs()),
],
),
],
)
def test_resolve_all_outputs(
self, tasks: Optional[list[Task]], result: list[Outputs]
):
"""
Test the `resolve_all_outputs` method of the `BeyondDFT` section.
"""
workflow = BeyondDFT()
if tasks is not None:
workflow.tasks = tasks
if result is not None:
for i, output in enumerate(workflow.resolve_all_outputs()):
assert output.name == result[i].name
else:
assert workflow.resolve_all_outputs() == result

1 comment on commit 07748d5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%57–59
   atoms_state.py1902189%31–33, 219–222, 246, 301–302, 370–371, 373, 555, 567–568, 629–633, 648–652, 659
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py89891%22–25, 139, 203, 313–314, 324
   model_method.py2657771%28–30, 189–192, 195–202, 294–295, 315, 336–357, 373–399, 402–419, 773, 784, 826–833, 871, 890, 970, 1027, 1102, 1216
   model_system.py3002392%43–45, 382, 577–580, 627–634, 808–809, 1030–1034, 1040–1041, 1049–1050, 1055, 1078
   numerical_settings.py2596176%30–32, 235, 237–238, 241–244, 248–249, 256–259, 268–271, 275–278, 280–283, 288–291, 297–300, 487–514, 589, 624–627, 651, 654, 699, 701–704, 708, 712, 759, 763–784, 839–840, 907
   outputs.py1201092%27–28, 270–273, 313–316, 341, 343, 380, 399
   physical_property.py102793%38–40, 220, 349–351
   variables.py861286%26–28, 116, 139, 163, 185, 207, 229, 251, 274, 294
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%26–28, 153–154
   band_structure.py1232580%27–29, 250–283, 296, 303, 339–340, 343, 390–391, 396
   energies.py42979%25–27, 54, 75, 100, 121, 137, 152
   fermi_surface.py17476%25–27, 58
   forces.py22673%26–28, 55, 75, 98
   greens_function.py991387%25–27, 228–229, 232, 253–254, 257, 278–279, 282, 418
   hopping_matrix.py29583%25–27, 76, 112
   permittivity.py48883%25–27, 115–123
   spectral_profile.py26012851%27–29, 75–78, 113–116, 217–318, 374–386, 411–414, 434, 439–442, 484–520, 544, 591–594, 610–611, 616–622
   thermodynamics.py752764%25–27, 53, 74, 90, 99, 108, 119, 128, 155, 165, 175, 190–192, 195, 211, 231–233, 236, 252, 272–274, 277
src/nomad_simulations/schema_packages/utils
   utils.py711579%27–32, 86–95, 104–105, 110, 113
src/nomad_simulations/schema_packages/workflow
   base_workflows.py51394%23–24, 154
   dft_plus_tb.py513629%23–24, 80–92, 98–119, 130–136, 139–166
   single_point.py362433%26–27, 57–73, 82–87, 90–102
TOTAL267056179% 

Tests Skipped Failures Errors Time
424 0 💤 0 ❌ 0 🔥 3.757s ⏱️

Please sign in to comment.