-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implementing phase space plugin in picmi #5278
Draft
mafshari64
wants to merge
10
commits into
ComputationalRadiationPhysics:dev
Choose a base branch
from
mafshari64:topic-phaseSpacePluginForPicmi
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a4a634
add phase_space.json
mafshari64 f142364
Fix formatting issues and add pypicongpu phase_space.py
mafshari64 a4437a1
adding PIConGPU PICMI interface for phase_space after ruff CRLF impr…
mafshari64 2c8d69a
improving phase_space parameter names
mafshari64 e978d45
correct path to phase_space interface
mafshari64 2f76a5f
adding phase_space block to picmi python script for lwfa
mafshari64 6b6bee2
correcting phase_space block param names
mafshari64 de3c459
pass species object instead of species name
mafshari64 a857226
fix buges-picmi to picongpu conversion in picongpu-picmi-phase_space.py
mafshari64 7801e5d
fix 2 buges-picmi to picongpu conversion in picongpu-picmi-phase_spac…
mafshari64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import picmistandard | ||
# print(dir(picmistandard)) # Check if PICMI_PhaseSpace is listed | ||
|
||
print(picmistandard.__file__) | ||
# /home/afshar87/.local/lib/python3.10/site-packages/picmistandard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
""" | ||
This file is part of PIConGPU. | ||
Copyright 2021-2024 PIConGPU contributors | ||
Authors: Masoud Afshari | ||
License: GPLv3+ | ||
""" | ||
|
||
from ..pypicongpu import util | ||
from ..pypicongpu.output.phase_space import PhaseSpace | ||
from ..pypicongpu.species.species import Species as PyPIConGPUSpecies | ||
|
||
|
||
from .species import Species as PICMISpecies | ||
|
||
import picmistandard | ||
import typeguard | ||
|
||
|
||
@typeguard.typechecked | ||
class PhaseSpace(picmistandard.PICMI_PhaseSpace): | ||
"""PICMI object for Phase Space diagnostics""" | ||
|
||
def __init__( | ||
self, | ||
species: PICMISpecies, | ||
period: int, | ||
spatial_coordinate: str, | ||
momentum: str, | ||
min_momentum: float, | ||
max_momentum: float, | ||
**kw, | ||
): | ||
if period <= 0: | ||
raise ValueError("Period must be > 0") | ||
if min_momentum >= max_momentum: | ||
raise ValueError("min_momentum must be less than max_momentum") | ||
|
||
self.species = species | ||
self.period = period | ||
self.spatial_coordinate = spatial_coordinate | ||
self.momentum = momentum | ||
self.min_momentum = min_momentum | ||
self.max_momentum = max_momentum | ||
|
||
super().__init__( | ||
species, | ||
period, | ||
spatial_coordinate, | ||
momentum, | ||
min_momentum, | ||
max_momentum, | ||
**kw, | ||
) | ||
|
||
def get_as_pypicongpu( | ||
# to get the corresponding PyPIConGPUSpecies instance for the given PICMISpecies. | ||
self, | ||
dict_species_picmi_to_pypicongpu: dict[PICMISpecies, PyPIConGPUSpecies], | ||
) -> PhaseSpace: | ||
# print(f"dict_species_picmi_to_pypicongpu keys: {list(dict_species_picmi_to_pypicongpu.keys())}") | ||
# print(f"self.species: {self.species}") | ||
|
||
util.unsupported("extra attributes", self.__dict__.keys()) | ||
|
||
if self.species not in dict_species_picmi_to_pypicongpu: | ||
raise ValueError(f"Species {self.species} is not mapped in dict_species_picmi_to_pypicongpu!") | ||
|
||
# checks if PICMISpecies instance exists in the dictionary. If yes, it returns the corresponding PyPIConGPUSpecies instance. | ||
# self.species refers to the species attribute of the class PhaseSpace(picmistandard.PICMI_PhaseSpace). | ||
pypicongpu_species = dict_species_picmi_to_pypicongpu.get(self.species) | ||
|
||
if pypicongpu_species is None: | ||
raise ValueError(f"Species {self.species} is not mapped to a PyPIConGPUSpecies.") | ||
|
||
# Print type before passing to PhaseSpace | ||
print(f"DEBUG: Mapped species: {pypicongpu_species}, Type: {type(pypicongpu_species)}") | ||
|
||
pypicongpu_phase_space = PhaseSpace( | ||
species=pypicongpu_species, | ||
period=self.period, | ||
spatial_coordinate=self.spatial_coordinate, | ||
momentum=self.momentum, | ||
min_momentum=self.min_momentum, | ||
max_momentum=self.max_momentum, | ||
) | ||
|
||
return pypicongpu_phase_space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
This file is part of PIConGPU. | ||
Copyright 2021-2024 PIConGPU contributors | ||
Authors: Masoud Afshari | ||
License: GPLv3+ | ||
""" | ||
|
||
from .. import util | ||
from ..species import Species | ||
|
||
from .plugin import Plugin | ||
|
||
import typeguard | ||
import typing | ||
from typing import Literal | ||
|
||
|
||
@typeguard.typechecked | ||
class PhaseSpace(Plugin): | ||
species = util.build_typesafe_property(Species) | ||
period = util.build_typesafe_property(int) | ||
spatial_coordinate = util.build_typesafe_property(Literal["x", "y", "z"]) | ||
momentum = util.build_typesafe_property(Literal["px", "py", "pz"]) | ||
min_momentum = util.build_typesafe_property(float) | ||
max_momentum = util.build_typesafe_property(float) | ||
|
||
def _get_serialized(self) -> typing.Dict: | ||
"""Return the serialized representation of the object.""" | ||
return { | ||
"species": self.species.get_cxx_typename(), | ||
"period": self.period, | ||
"spatial_coordinate": self.spatial_coordinate, | ||
"momentum": self.momentum, | ||
"min_momentum": self.min_momentum, | ||
"max_momentum": self.max_momentum, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
This file is part of PIConGPU. | ||
Copyright 2021-2024 PIConGPU contributors | ||
Authors: Brian Edward Marre, Masoud Afshari | ||
License: GPLv3+ | ||
""" | ||
|
||
from ..rendering import RenderedObject | ||
|
||
import typeguard | ||
|
||
|
||
@typeguard.typechecked | ||
class Plugin(RenderedObject): | ||
"""general interface for all plugins""" | ||
|
||
def __init__(self): | ||
raise NotImplementedError("abstract base class only") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could implement as a safeguard a constructor to make sure nobody instantiates the base class directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you mean RuntimeError instead of RunTimeError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but I'd rather suggest using
NotImplementedError
. That's more specific.