How rafael-fuente/diffractsim works
Main Components
• Core Simulation Engine (the diffractsim package): This is the nucleus of your project. Within this package, several submodules implement the optical simulation functionalities:
• diffractsim/diffractive_elements: Contains various modules that define apertures, gratings, lenses, and other diffractive optical elements (e.g., circular_aperture, axial and hexagonal apertures, Fresnel zone plate, etc.).
• diffractsim/holography: Implements phase retrieval techniques including both Fourier and custom solutions for holographic reconstruction.
• diffractsim/light_sources: Provides modules for different light sources including plane waves, Gaussian beams, and spatial noise.
• diffractsim/polynomials: Contains modules for Hermite-Gaussian, Laguerre-Gaussian modes, and Zernike polynomials, important for representing beam characteristics.
• diffractsim/propagation_methods: Includes several methods for simulating light propagation (e.g., angular spectrum, Bluestein, two-steps Fresnel), forming the computational backbone.
• diffractsim/util: Provides utility functions for backend computations, file and image handling, FFT optimizations with Bluestein and Chirp-Z transforms, and constant definitions.
• diffractsim/visualization: Offers modules to process simulation outputs into visual representations such as intensity plots, phase plots, and longitudinal intensity profiles.
• Simulation Interfaces: Entry points like “diffractsim/monochromatic_simulator.py” and “diffractsim/polychromatic_simulator.py” indicate different simulation setups.
• Examples: The “examples” directory demonstrates end-to-end usage of the simulation engine. Each script (e.g., “hexagon_monochromatic.py”, “bahtinov_mask.py”) serves as a practical use case, highlighting how the different modules come together.
• GPU Acceleration & Differentiable Programming: The README describes the use of JAX or CuPy, which are integrated via a backend switch (e.g., diffractsim.set_backend("JAX")). This supports high-performance computations and optimization workflows.
Relationships and Interactions
• Architectural layers:
• At the top, you have the simulation interface modules (entry points in examples and main simulation scripts).
• The next layer is the core engine (the diffractsim package) segmented into its various logical submodules.
• Between these modules, denote the data flow: for example, Light Source → Diffractive Elements → Propagation (via chosen propagation method) → Visualization.
• Link the GPU acceleration component to the “util” module and overall simulation engine, indicating that the backend (JAX/CuPy) affects performance and differentiability.
• That configuration, spectrum data (files in the “data” folder), and optical components (diffractive_elements) feed into the simulation computations performed by propagation_methods.
Architectural Patterns and Technologies
• Modularity: Each optical element and computational method is encapsulated in its own module. Emphasize separation of concerns.
• Extensibility: The presence of different diffractive elements, light sources, and propagation methods indicates plugin-style extensibility.
• Performance Considerations: Highlight the optional GPU acceleration integration (CuPy, JAX) and potential for parallel computation when generating longitudinal profiles.
• Reusability: Utility functions and backend abstraction allow the simulator to operate in different computational contexts.