Skip to content

qiu_classical_simulation.wave_optics.parameters

The parameters of a lens experiment: a Gaussian beam through a plano-convex lens.

A Gaussian beam of a waist given by its FWHM enters a plano-convex lens, sliced along the optical axis into thin transparent plates, and then propagates freely behind it. The transverse field is sampled on 2**num_qubits points of a window of transverse_length, which the lens fills.

Classes:

Attributes:

  • LEGACY_KEYS –

    Former names of stored parameters, mapped to the current ones.

  • LEGACY_DEFAULTS (dict[str, Any]) –

    Values of parameters missing in older results, which always used them.

LEGACY_KEYS module-attribute

LEGACY_KEYS = {'timestamp': 'experiment_datetime', 'reverse_order': 'lens_reverse_order'}

Former names of stored parameters, mapped to the current ones.

LEGACY_DEFAULTS module-attribute

LEGACY_DEFAULTS: dict[str, Any] = {'direct_propagator': True, 'uuid': ''}

Values of parameters missing in older results, which always used them.

ExperimentParameters dataclass

ExperimentParameters(vacuum_wavelength: float, beam_FWHM: float, focal_length: float, refractive_index: float, propagation_after_lens: float, transverse_length: float, num_of_steps_after_lens: int, lens_slices: int, num_qubits: int, max_delta: float, lens_reverse_order: bool, fresnel_approximation: bool, scale_down_phases: bool, direct_propagator: bool, experiment_datetime: datetime = now(), uuid: str = (lambda: hex)())

The parameters of a lens experiment, from which all others are derived.

Methods:

  • validity_problems –

    Return the violated conditions of the sampling and the paraxial regime.

  • is_valid –

    Whether the parameters satisfy the conditions of validity_problems.

  • to_dict –

    Return the parameters, with the derived lens geometry, as JSON values.

  • from_dict –

    Create the parameters from stored values, e.g. of to_dict.

Attributes:

vacuum_wavelength instance-attribute

vacuum_wavelength: float

beam_FWHM instance-attribute

beam_FWHM: float

focal_length instance-attribute

focal_length: float

refractive_index instance-attribute

refractive_index: float

propagation_after_lens instance-attribute

propagation_after_lens: float

transverse_length instance-attribute

transverse_length: float

num_of_steps_after_lens instance-attribute

num_of_steps_after_lens: int

lens_slices instance-attribute

lens_slices: int

num_qubits instance-attribute

num_qubits: int

The number of qubits n of the 2**n transverse samples.

max_delta instance-attribute

max_delta: float

The maximum phase per cycle of the sample-based phase protocol.

lens_reverse_order instance-attribute

lens_reverse_order: bool

If True, the beam enters through the plane side of the lens.

fresnel_approximation instance-attribute

fresnel_approximation: bool

If True, the lens surface is approximated by a paraboloid.

scale_down_phases instance-attribute

scale_down_phases: bool

If True, the phases of the lens slices are reduced modulo 2 pi.

direct_propagator instance-attribute

direct_propagator: bool

If True, free propagation is applied directly, else with the phase protocol.

experiment_datetime class-attribute instance-attribute

experiment_datetime: datetime = field(default_factory=datetime.now)

uuid class-attribute instance-attribute

uuid: str = field(default_factory=lambda: uuid.uuid4().hex)

k0 cached property

k0: float

The vacuum wavenumber.

reduced_wavelength cached property

reduced_wavelength: float

The wavelength inside the lens.

radius_of_curvature cached property

radius_of_curvature: float

The radius of curvature of the convex surface, from the lensmaker's equation.

lens_diameter cached property

lens_diameter: float

The diameter of the lens, filling the transverse window.

lens_radius cached property

lens_radius: float

The transverse radius of the lens.

lens_thickness cached property

lens_thickness: float

The thickness of the lens at its center.

dimension cached property

dimension: int

The number of transverse samples.

delta_x cached property

delta_x: float

The transverse sampling period.

gaussian_mean cached property

gaussian_mean: float

The transverse position of the beam's center, the center of the window.

gaussian_beam_waist cached property

gaussian_beam_waist: float

The waist radius of the beam, from its FWHM.

lens_slice_thickness cached property

lens_slice_thickness: float

The thickness of each lens slice.

step_size_after_lens cached property

step_size_after_lens: float

The length of each free propagation step behind the lens.

lens_slice_positions cached property

lens_slice_positions: NDArray[float64]

The depths of the midpoints of the lens slices, from the vertex.

lens_transverse_radii cached property

lens_transverse_radii: list[float]

The transverse radii of the lens slices, from the vertex.

x_axis cached property

x_axis: PositionAxis

The transverse position axis, from 0 to transverse_length.

k_axis cached property

The angular wavenumber axis of the angular spectrum, in the FFT ordering.

initial_beam_profile cached property

initial_beam_profile: AlgebraicSignal

The field of the Gaussian beam entering the lens.

initial_state cached property

initial_state: NDArray[complex128]

The normalized amplitudes of the beam entering the lens.

lens_signals cached property

lens_signals: list[AlgebraicSignal]

The phase signals of the lens slices, from the vertex.

ordered_lens_signals cached property

ordered_lens_signals: list[AlgebraicSignal]

The phase signals of the lens slices, in the order the beam passes them.

validity_problems

validity_problems() -> list[str]

Return the violated conditions of the sampling and the paraxial regime.

Source code in packages/qiu-classical-simulation/src/qiu_classical_simulation/wave_optics/parameters.py
65
66
67
68
69
70
71
72
73
74
75
76
77
def validity_problems(self) -> list[str]:
    """Return the violated conditions of the sampling and the paraxial regime."""
    problems = []
    if self.delta_x > self.vacuum_wavelength:
        problems.append(
            f"delta_x > vacuum_wavelength: {self.delta_x} > {self.vacuum_wavelength}"
        )
    if self.gaussian_beam_waist < 10 * self.vacuum_wavelength:
        problems.append(
            "gaussian_beam_waist < 10 * vacuum_wavelength (paraxial regime): "
            f"{self.gaussian_beam_waist} < {10 * self.vacuum_wavelength}"
        )
    return problems

is_valid

is_valid() -> bool

Whether the parameters satisfy the conditions of validity_problems.

Source code in packages/qiu-classical-simulation/src/qiu_classical_simulation/wave_optics/parameters.py
79
80
81
def is_valid(self) -> bool:
    """Whether the parameters satisfy the conditions of `validity_problems`."""
    return not self.validity_problems()

to_dict

to_dict() -> dict[str, Any]

Return the parameters, with the derived lens geometry, as JSON values.

Source code in packages/qiu-classical-simulation/src/qiu_classical_simulation/wave_optics/parameters.py
216
217
218
219
220
221
222
def to_dict(self) -> dict[str, Any]:
    """Return the parameters, with the derived lens geometry, as JSON values."""
    values = asdict(self)
    values["experiment_datetime"] = self.experiment_datetime.isoformat()
    values["lens_diameter"] = self.lens_diameter
    values["lens_thickness"] = self.lens_thickness
    return values

from_dict classmethod

from_dict(values: dict[str, Any], defaults: dict[str, Any] | None = None) -> ExperimentParameters

Create the parameters from stored values, e.g. of to_dict.

Values of results stored under former names (LEGACY_KEYS) are renamed, and LEGACY_DEFAULTS fill in parameters which older results did not store.

Parameters:

  • values (dict[str, Any]) –

    The stored values; unknown keys, e.g. derived ones, are ignored.

  • defaults (dict[str, Any] | None, default: None ) –

    Values for parameters missing in values, e.g. those an older simulation did not store but used.

Returns:

Raises:

  • KeyError –

    If parameters are missing in values, defaults and LEGACY_DEFAULTS.

Source code in packages/qiu-classical-simulation/src/qiu_classical_simulation/wave_optics/parameters.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@classmethod
def from_dict(
    cls, values: dict[str, Any], defaults: dict[str, Any] | None = None
) -> "ExperimentParameters":
    """Create the parameters from stored values, e.g. of `to_dict`.

    Values of results stored under former names (`LEGACY_KEYS`) are renamed, and
    `LEGACY_DEFAULTS` fill in parameters which older results did not store.

    Args:
        values: The stored values; unknown keys, e.g. derived ones, are ignored.
        defaults: Values for parameters missing in `values`, e.g. those an older
            simulation did not store but used.

    Returns:
        The parameters.

    Raises:
        KeyError: If parameters are missing in `values`, `defaults` and
            `LEGACY_DEFAULTS`.
    """
    renamed = {LEGACY_KEYS.get(key, key): value for key, value in values.items()}
    merged = {**LEGACY_DEFAULTS, **(defaults or {}), **renamed}
    names = [f.name for f in fields(cls)]
    missing = [name for name in names if name not in merged]
    if missing:
        raise KeyError(
            f"Missing parameters {missing}; give their values as defaults."
        )
    arguments = {name: merged[name] for name in names}
    if isinstance(arguments["experiment_datetime"], str):
        arguments["experiment_datetime"] = datetime.fromisoformat(
            arguments["experiment_datetime"]
        )
    return cls(**arguments)