Skip to content

Commit

Permalink
WIP use hdf5_metno and pyo3 0.22 for ndarray 0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Nov 12, 2024
1 parent 9b92b97 commit ef2b43c
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 265 deletions.
574 changes: 327 additions & 247 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Sammy McSweeney <sammy.mcsweeney@gmail.com>",
]
edition = "2021"
rust-version = "1.65"
rust-version = "1.80"
license = "MPL-2.0"
readme = "README.md"
description = "Primary beam code for the Murchison Widefield Array (MWA) radio telescope."
Expand All @@ -28,7 +28,7 @@ crate-type = ["rlib", "staticlib", "cdylib"]

[features]
default = []
hdf5-static = ["hdf5-sys"]
hdf5-static = ["hdf5-metno-sys"]
cuda-static = []
all-static = ["hdf5-static", "cuda-static"]
python = ["pyo3", "numpy"]
Expand All @@ -47,7 +47,7 @@ codegen-units = 1 # Set this to 1 in Cargo.toml to allow for maximum size reduct

[dependencies]
cfg-if = "1.0.0"
hdf5 = "0.8.0"
hdf5-metno = "0.9.2"
marlu = { version = "0.15.0", default-features = false } # don't forget dev-dependencies
ndarray = "0.16.0"
num-complex = "0.4.1"
Expand All @@ -56,7 +56,7 @@ parking_lot = "0.12.0"
rayon = "1.5.0"
thiserror = "1.0.2"

hdf5-sys = { version = "0.8.0", features = [
hdf5-metno-sys = { version = "0.9.1", features = [
"static",
"threadsafe",
], optional = true }
Expand All @@ -65,8 +65,8 @@ cuda-runtime-sys = { version = "0.3.0-alpha.1", optional = true }

hip-sys = { version = "0.1.0", optional = true }

pyo3 = { version = "0.19.1", features = ["extension-module"], optional = true }
numpy = { version = "0.19.0", optional = true }
pyo3 = { version = "0.22.0", features = ["extension-module"], optional = true }
numpy = { version = "0.22.1", optional = true }

[dev-dependencies]
approx = { version = "0.5.0", features = ["num-complex"] }
Expand Down
1 change: 1 addition & 0 deletions examples/analytic_cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
norm_to_zenith,
)?;

#[allow(clippy::useless_conversion)]
let diff = jones[(0, 0, 0)] - Jones::<GpuFloat>::from(jones_cpu);

println!("Difference between first GPU and CPU Jones matrices");
Expand Down
1 change: 1 addition & 0 deletions examples/fee_cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
iau_order,
)?;

#[allow(clippy::useless_conversion)]
let diff = jones[(0, 0, 0)] - Jones::<GpuFloat>::from(jones_cpu);

println!("Difference between first GPU and CPU Jones matrices");
Expand Down
2 changes: 1 addition & 1 deletion src/analytic/gpu/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn test_cram() {
);
let gpu_results = result.unwrap();
#[cfg(feature = "gpu-single")]
let gpu_results = gpu_results.mapv(|j| Jones::<f64>::from(j));
let gpu_results = gpu_results.mapv(Jones::<f64>::from);

// Compare with CPU.
let cpu_results = beam
Expand Down
8 changes: 4 additions & 4 deletions src/fee/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub enum InitFEEBeamError {
#[error("Unexpected array shape when reading HDF5 dataset 'modes': expected 3 rows")]
ModesShape,

/// An error associated with the hdf5 crate.
/// An error associated with the hdf5_metno crate.
#[error("HDF5 error: {0}")]
Hdf5(#[from] hdf5::Error),
Hdf5(#[from] hdf5_metno::Error),
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -66,9 +66,9 @@ pub enum FEEBeamError {
#[error("The number of delays wasn't 16 (got {rows} tiles with {num_delays} each); each tile's 16 delays these must correspond to bowties in the M&C order")]
IncorrectDelaysArrayColLength { rows: usize, num_delays: usize },

/// An error associated with the hdf5 crate.
/// An error associated with the hdf5_metno crate.
#[error("HDF5 error: {0}")]
Hdf5Error(#[from] hdf5::Error),
Hdf5Error(#[from] hdf5_metno::Error),

#[cfg(any(feature = "cuda", feature = "hip"))]
#[error(transparent)]
Expand Down
10 changes: 5 additions & 5 deletions src/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ use crate::{
/// The main struct to be used for calculating Jones matrices.
#[allow(clippy::upper_case_acronyms)]
pub struct FEEBeam {
/// The [`hdf5::File`] struct associated with the opened HDF5 file. It is
/// The [`hdf5_metno::File`] struct associated with the opened HDF5 file. It is
/// behind a [`Mutex`] to prevent parallel usage of the file.
hdf5_file: Mutex<hdf5::File>,
hdf5_file: Mutex<hdf5_metno::File>,
/// An ascendingly-sorted vector of frequencies available in the HDF5 file.
/// Not allowed to be empty.
freqs: Vec<u32>,
Expand All @@ -61,16 +61,16 @@ impl FEEBeam {
/// Given the path to an FEE beam file, create a new [`FEEBeam`] struct.
pub fn new<T: AsRef<std::path::Path>>(file: T) -> Result<Self, InitFEEBeamError> {
// so that libhdf5 doesn't print errors to stdout
hdf5::silence_errors(true);
hdf5_metno::silence_errors(true);

// If the file doesn't exist, hdf5::File::open will handle it, but the
// If the file doesn't exist, hdf5_metno::File::open will handle it, but the
// error message is horrendous.
if !file.as_ref().exists() {
return Err(InitFEEBeamError::BeamFileDoesntExist(
file.as_ref().display().to_string(),
));
}
let h5 = hdf5::File::open(file)?;
let h5 = hdf5_metno::File::open(file)?;
// We want all of the available frequencies and the biggest antenna index.
let mut freqs: Vec<u32> = vec![];
let mut biggest_dip_index: Option<u8> = None;
Expand Down
4 changes: 2 additions & 2 deletions src/fee/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn new() {
#[test]
#[serial]
fn new_from_env() {
std::env::set_var("MWA_BEAM_FILE", "mwa_full_embedded_element_pattern.h5");
unsafe { std::env::set_var("MWA_BEAM_FILE", "mwa_full_embedded_element_pattern.h5") };
let beam = FEEBeam::new_from_env();
assert!(beam.is_ok());
}
Expand Down Expand Up @@ -939,7 +939,7 @@ fn test_error_file_doesnt_exist() {
#[test]
fn test_error_env_file_doesnt_exist() {
let file = "/unlikely/to/exist/again.h5";
std::env::set_var("MWA_BEAM_FILE", file);
unsafe { std::env::set_var("MWA_BEAM_FILE", file) };
let result = FEEBeam::new_from_env();
assert!(result.is_err());
match result {
Expand Down

0 comments on commit ef2b43c

Please sign in to comment.