Skip to main content

PyPDF

Struct PyPDF 

Source
pub struct PyPDF { /* private fields */ }
Expand description

Python wrapper for the neopdf::pdf::PDF struct.

This class provides a Python-friendly interface to the core PDF interpolation functionalities of the neopdf Rust library.

Implementations§

Source§

impl PyPDF

Source

pub fn new(pdf_name: &str, member: usize) -> Self

Creates a new PDF instance for a given PDF set and member.

This is the primary constructor for the PDF class.

§Parameters

pdf_name : str The name of the PDF set. member : int The ID of the PDF member to load. Defaults to 0.

§Returns

PDF A new PDF instance.

Source

pub fn mkpdf(pdf_name: &str, member: usize) -> Self

Loads a given member of the PDF set.

This is an alternative constructor for convenience, equivalent to PDF(pdf_name, member).

§Parameters

pdf_name : str The name of the PDF set. member : int The ID of the PDF member. Defaults to 0.

§Returns

PDF A new PDF instance.

Source

pub fn mkpdf_lhaid(lhaid: u32) -> Self

Loads a PDF member by its LHAPDF ID (LHAID).

The set name and member index are resolved by fetching the LHAPDF set index from https://lhapdfsets.web.cern.ch/current/pdfsets.index.

§Parameters

lhaid : int The LHAPDF ID uniquely identifying both the PDF set and the member.

§Returns

PDF A new PDF instance for the set and member encoded in lhaid.

Source

pub fn mkpdf_lhapdf_file(path: &str) -> Self

Loads a PDF member from a specific LHAPDF .dat file path.

§Parameters

path : str The path to the LHAPDF .dat file.

§Returns

PDF A new PDF instance for the specified file.

Source

pub fn mkpdfs(pdf_name: &str, method: &PyLoaderMethod) -> Vec<Self>

Loads all members of the PDF set.

This function loads all available members for a given PDF set, returning a list of PDF instances.

§Parameters

pdf_name : str The name of the PDF set.

§Returns

listPDF A list of PDF instances, one for each member.

Source

pub fn mkpdfs_lazy(pdf_name: &str) -> PyLazyPDFs

Creates an iterator that loads PDF members lazily.

This function is suitable for .neopdf.lz4 files, which support lazy loading. It returns an iterator that yields PDF instances on demand, which is useful for reducing memory consumption when working with large PDF sets.

§Arguments
  • pdf_name - The name of the PDF set (must end with .neopdf.lz4).
§Returns

An iterator over Result<PDF, Box<dyn std::error::Error>>.

Source

pub fn pids(&self) -> Vec<i32>

Returns the list of PID values.

§Returns

list[int] The PID values.

Source

pub fn subgrids(&self) -> Vec<PySubGrid>

Returns the list of Subgrid objects.

§Returns

list[PySubgrid] The subgrids.

Source

pub fn subgrid_knots( &self, param: &PyGridParams, subgrid_index: usize, ) -> Vec<f64>

Returns the subgrid knots of a parameter for a given subgrid index.

The parameter could be the nucleon numbers A, the strong coupling alphas, the momentum fraction x, or the momentum scale Q2.

§Panics

This panics if the parameter is not valid.

§Returns

list[float] The subgrid knots for a given parameter.

Source

pub fn set_force_positive(&mut self, option: PyForcePositive)

Clip the negative or small values for the PDF object.

§Parameters

id : PyFrocePositive The clipping method use to handle negative or small values.

Source

pub fn set_force_positive_members( pdfs: Vec<PyRefMut<'_, Self>>, option: PyForcePositive, )

Clip the negative or small values for all the PDF objects.

§Parameters

pdfs : listPDF A list of PDF instances. option : PyForcePositive The clipping method use to handle negative or small values.

Source

pub fn is_force_positive(&self) -> PyForcePositive

Returns the clipping method used for a single PDF object.

§Returns

PyForcePositive The clipping method used for the PDF object.

Source

pub fn x_min(&self) -> f64

Retrieves the minimum x-value for this PDF set.

§Returns

float The minimum x-value.

Source

pub fn x_max(&self) -> f64

Retrieves the maximum x-value for this PDF set.

§Returns

float The maximum x-value.

Source

pub fn q2_min(&self) -> f64

Retrieves the minimum Q2-value for this PDF set.

§Returns

float The minimum Q2-value.

Source

pub fn q2_max(&self) -> f64

Retrieves the maximum Q2-value for this PDF set.

§Returns

float The maximum Q2-value.

Source

pub fn flavour_pids(&self) -> Vec<i32>

Retrieves the flavour PIDs for the PDF set.

§Returns

list(int) The flavour PID values.

Source

pub fn xfxq2(&self, id: i32, x: f64, q2: f64) -> f64

Interpolates the PDF value (xf) for a given flavor, x, and Q2.

§Parameters

id : int The flavor ID (e.g., 21 for gluon, 1 for d-quark). x : float The momentum fraction. q2 : float The energy scale squared.

§Returns

float The interpolated PDF value. Returns 0.0 if extrapolation is attempted and not allowed.

Source

pub fn xfxq2_nd(&self, id: i32, params: Vec<f64>) -> f64

Interpolates the PDF value (xf) for a given set of parameters.

§Parameters

id : int The flavor ID (e.g., 21 for gluon, 1 for d-quark). params: list[float] A list of parameters that the grids depends on. If the PDF grid only contains x and Q2 dependence then its value is [x, q2]; if it contains either the A and alpha_s dependence, then its value is [A, x, q2] or [alpha_s, x, q2] respectively; if it contains both, then [A, alpha_s, x, q2].

§Returns

float The interpolated PDF value. Returns 0.0 if extrapolation is attempted and not allowed.

Source

pub fn xfxq2_allpids<'py>( &self, pids: Vec<i32>, x: f64, q2: f64, py: Python<'py>, ) -> Bound<'py, PyArray1<f64>>

Evaluates all requested flavors at a single kinematic point.

§Parameters

pids : list[int] A list of flavor IDs. x : float The momentum fraction. q2 : float The energy scale squared.

§Returns

numpy.ndarray A 1D NumPy array containing the interpolated PDF values for each PID.

Source

pub fn xfxq2_allpids_nd<'py>( &self, pids: Vec<i32>, params: Vec<f64>, py: Python<'py>, ) -> Bound<'py, PyArray1<f64>>

Evaluates all requested flavors at a single kinematic point.

§Parameters

pids : list[int] A list of flavor IDs. params : list[float] A list of parameters (e.g., [kT, x, q2]).

§Returns

numpy.ndarray A 1D NumPy array containing the interpolated PDF values for each PID.

Source

pub fn xfxq2_cheby_batch(&self, id: i32, params: Vec<Vec<f64>>) -> Vec<f64>

Interpolates the PDF value (xf) for a list containg a set of parameters.

§Parameters

id : int The flavor ID (e.g., 21 for gluon, 1 for d-quark). params: list[list[float]] A list containing the list of points. Each element in the list is in turn a list containing the parameters that the grids depends on. If the PDF grid only contains x and Q2 dependence then its value is [x, q2]; if it contains either the A and alpha_s dependence, then its value is [A, x, q2] or [alpha_s, x, q2] respectively; if it contains both, then [A, alpha_s, x, q2].

§Returns

float The interpolated PDF value. Returns 0.0 if extrapolation is attempted and not allowed.

Source

pub fn xfxq2s<'py>( &self, pids: Vec<i32>, xs: Vec<f64>, q2s: Vec<f64>, py: Python<'py>, ) -> Bound<'py, PyArray2<f64>>

Interpolates the PDF value (xf) for lists of flavors, x-values, and Q2-values.

§Parameters

id : list[int] A list of flavor IDs. xs : list[float] A list of momentum fractions. q2s : list[float] A list of energy scales squared.

§Returns

numpy.ndarray A 2D NumPy array containing the interpolated PDF values.

Source

pub fn alphas_q2(&self, q2: f64) -> f64

Computes the alpha_s value at a given Q2.

§Parameters

q2 : float The energy scale squared.

§Returns

float The interpolated alpha_s value.

Source

pub fn metadata(&self) -> PyMetaData

Returns the metadata associated with this PDF set.

Provides access to the metadata describing the PDF set, including information such as the set description, number of members, parameter ranges, and other relevant details.

§Returns

MetaData The metadata for this PDF set as a MetaData Python object.

Source

pub fn xfxq(&self, id: i32, x: f64, q: f64) -> f64

Evaluate xf(x, Q) for a single flavor.

Source

pub fn alphas_q(&self, q: f64) -> f64

Evaluate alpha_s(Q).

Source

pub fn flavors(&self) -> Vec<i32>

Return the list of available flavor PIDs (LHAPDF name for pids).

Source

pub fn has_flavor(&self, id: i32) -> bool

Return True if the given PID is available in this set.

Source

pub fn in_range_x(&self, x: f64) -> bool

Return True if x lies within the grid x-range.

Source

pub fn in_range_q(&self, q: f64) -> bool

Return True if Q (not Q²) lies within the grid Q-range.

Source

pub fn in_range_q2(&self, q2: f64) -> bool

Return True if lies within the grid Q²-range.

Source

pub fn in_range_xq(&self, x: f64, q: f64) -> bool

Return True if both x and Q are within their respective ranges.

Source

pub fn in_range_xq2(&self, x: f64, q2: f64) -> bool

Return True if both x and are within their respective ranges.

Source

pub const fn member_id(&self) -> usize

Index of this member within its PDF set (0 = central value).

Source

pub fn lhapdf_id(&self) -> u32

LHAPDF ID of this specific member (set base ID + member index).

Source

pub fn order_qcd(&self) -> u32

QCD perturbative order used for this PDF set.

Source

pub fn x_max_lhapdf(&self) -> f64

Maximum x value in the grid (camelCase LHAPDF alias).

Source

pub fn x_min_lhapdf(&self) -> f64

Minimum x value in the grid (camelCase LHAPDF alias).

Source

pub fn q2_max_lhapdf(&self) -> f64

Maximum Q² value in the grid (camelCase LHAPDF alias).

Source

pub fn q2_min_lhapdf(&self) -> f64

Minimum Q² value in the grid (camelCase LHAPDF alias).

Source

pub fn quark_mass(&self, id: i32) -> f64

Pole mass of the quark with the given flavor ID.

Returns 0.0 for unknown flavor IDs.

Source

pub fn quark_threshold(&self, id: i32) -> f64

Flavor threshold for the given quark ID (equal to the quark mass).

Source

pub fn description(&self) -> String

Human-readable description of this PDF set.

Source

pub fn set(&self) -> Option<PyPDFSet>

Return the PDFSet this member belongs to.

Only available when the PDF was loaded by name; returns None when loaded via LHAID or file path.

Source

pub fn has_key(&self, key: &str) -> bool

Return True if the given LHAPDF-canonical key is present in this PDF’s metadata.

Source

pub fn get_entry(&self, key: &str) -> PyResult<String>

Return the string value for an LHAPDF-canonical metadata key.

§Errors

Raises KeyError if the key is not present.

Source

pub fn keys(&self) -> Vec<String>

Return a sorted list of all available LHAPDF-canonical metadata keys.

Trait Implementations§

Source§

impl DerefToPyAny for PyPDF

Source§

impl ExtractPyClassWithClone for PyPDF

Source§

impl<'py> IntoPyObject<'py> for PyPDF

Source§

type Target = PyPDF

The Python output type
Source§

type Output = Bound<'py, <PyPDF as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

The type returned in the event of a conversion error.
Source§

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl PyClass for PyPDF

Source§

const NAME: &str = "PDF"

Name of the class. Read more
Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for PyPDF

Source§

const MODULE: Option<&str> = ::core::option::Option::None

Module which the class will be associated with. Read more
Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

const RAW_DOC: &'static CStr = /// Python wrapper for the `neopdf::pdf::PDF` struct. /// /// This class provides a Python-friendly interface to the core PDF /// interpolation functionalities of the `neopdf` Rust library.

Docstring for the class provided on the struct or enum. Read more
Source§

const DOC: &'static CStr

Fully rendered class doc, including the text_signature if a constructor is defined. Read more
Source§

type Layout = <<PyPDF as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<PyPDF>

Description of how this class is laid out in memory
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = NoopThreadChecker

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<PyObjectOffset>

Used to provide the dictoffset slot (equivalent to tp_dictoffset)
Source§

fn weaklist_offset() -> Option<PyObjectOffset>

Used to provide the weaklistoffset slot (equivalent to tp_weaklistoffset
Source§

impl PyClassNewTextSignature for PyPDF

Source§

const TEXT_SIGNATURE: &'static str = "(pdf_name, member=0)"

Source§

impl PyMethods<PyPDF> for PyClassImplCollector<PyPDF>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for PyPDF

Source§

const NAME: &str = <Self as ::pyo3::PyClass>::NAME

👎Deprecated since 0.28.0:

prefer using ::type_object(py).name() to get the correct runtime value

Class name.
Source§

const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE

👎Deprecated since 0.28.0:

prefer using ::type_object(py).module() to get the correct runtime value

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for PyPDF

§

impl !UnwindSafe for PyPDF

§

impl Freeze for PyPDF

§

impl Send for PyPDF

§

impl Sync for PyPDF

§

impl Unpin for PyPDF

§

impl UnsafeUnpin for PyPDF

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

Source§

const NAME: &'static str = T::NAME

👎Deprecated since 0.27.0:

Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.

Name of self. This is used in error messages, for example.
Source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>

Returns the expected type as a possible argument for the isinstance and issubclass function. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,