picongpu.pypicongpu.rendering.renderedobject

This file is part of PIConGPU. Copyright 2021-2025 PIConGPU contributors Authors: Hannes Troepgen, Brian Edward Marre, Julian Lenz License: GPLv3+

Classes

RenderedObject

Class to be inherited from for rendering context generation

SelfRegistering

A parent class the children of which will register their names in a list.

SelfRegisteringRenderedObject

A rendered object specialisation for grouping together self-registered subclasses.

Module Contents

class picongpu.pypicongpu.rendering.renderedobject.RenderedObject

Class to be inherited from for rendering context generation

Every object that intends to generate a rendering context (typically as a dict) must inherit from this class and implement _get_serialized().

It is expected that _get_serialized() fully encodes the internal state, i.e. two equal (==) objects also return an equal result for _get_serialized().

For external usage, the method get_rendering_context() is provided. It passes _get_serialized() through, checking its result against a predefined json schema. If this schema is not fullfilled/not available, an error is raised.

__hash__()

custom hash function for indexing in dicts

get_rendering_context() dict | None

get rendering context representation of this object

delegates work to _get_serialized and invokes checks performed by check_context_for_type(). :raise ValidationError: on schema violation :raise RuntimeError: on schema not found :return: self as rendering context

static check_context_for_type(type_to_check: type, context: dict | None)

check if the given context is valid for the given type

Raises on error, passes silently if okay.

Raises:
  • ValidationError – on schema violation

  • RuntimeError – on schema not found

class picongpu.pypicongpu.rendering.renderedobject.SelfRegistering

A parent class the children of which will register their names in a list.

Any subclass that wants to register has to overwrite _name. Its name will appear in _names afterwards.

Only leafs of the inheritance tree should have a _name. Everything else is undefined behaviour.

classmethod __init_subclass__()
class picongpu.pypicongpu.rendering.renderedobject.SelfRegisteringRenderedObject

Bases: RenderedObject, SelfRegistering

Inheritance diagram of picongpu.pypicongpu.rendering.renderedobject.SelfRegisteringRenderedObject

A rendered object specialisation for grouping together self-registered subclasses.

This class can be used like a RenderedObject but inheriting from this will create a new group of subclasses that are grouped into a category like Plugin, DensityProfile, etc.

Typically, the class inheriting from this doesn’t contain any functionality on its own but is purely for grouping, so class Plugin(SelfRegisteringRenderedObject): pass is a valid intermediate layer in the inheritance tree for grouping together plugins.

classmethod __init_subclass__()
get_rendering_context()

retrieve a generic context containing type information specifying a subclass

Problem: Every self-registered subclass has its respective schema, and it is difficult in JSON (particularly in a mustache-compatible way) to get the type of the schema.

Solution: The normal rendering of self-registered subclasses via get_rendering_context() provides only their parameters, i.e. there is no meta information on types etc.

If a generic context is requested one can use the schema for parent class, for which this method returns the correct content. It includes metainformation and the data on the schema itself.

E.g.:

{
    "type": {
        "phasespace": true,
        "auto": false,
        ...
    },
    "data": DATA
}

where DATA is the serialization as returned by get_rendering_context().

__hash__()

custom hash function for indexing in dicts

static check_context_for_type(type_to_check: type, context: dict | None)

check if the given context is valid for the given type

Raises on error, passes silently if okay.

Raises:
  • ValidationError – on schema violation

  • RuntimeError – on schema not found