Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporating skycleaver functionality to skyweaver #20

Open
wants to merge 52 commits into
base: pipeline_dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
81bad82
First draft of the skycleaver implementation
vivekvenkris Aug 22, 2024
efeffb7
Change source name and position from default values in header
vivekvenkris Aug 22, 2024
63c854b
seek to the correct timestamp
vivekvenkris Sep 3, 2024
0201f7e
use uint8 for filterbank output
vivekvenkris Sep 4, 2024
331c1cf
Correct frequency tagging of tdb outputs
vivekvenkris Sep 4, 2024
5dc0bf4
swap beam and dm loops, convert signed to unsigned by rescaling data
vivekvenkris Sep 4, 2024
ccc6ebb
Merge commit '218f424562ce85a08af871551ef01183a00f91e0' into skycleaver
vivekvenkris Sep 4, 2024
a823587
add has key, get_or_default methods to header
vivekvenkris Sep 11, 2024
e14fc64
get-> get_or_default for few keys
vivekvenkris Sep 11, 2024
4f72d08
add basefilename to multifilewriterconfig and change it as needed in …
vivekvenkris Sep 11, 2024
36b1271
reuse bytes_seeking
vivekvenkris Sep 11, 2024
b36cb9f
reflect file writer callback changes in tester
vivekvenkris Sep 11, 2024
4826368
fix paths and filenames
vivekvenkris Sep 19, 2024
4aec59b
check for both OBS_FREQ & OBS_FREQUENCY
vivekvenkris Sep 19, 2024
2462dad
proper naming, more header parameters to read from dada files
vivekvenkris Sep 20, 2024
c55bf3c
get mjd_start from utc_offset
vivekvenkris Sep 20, 2024
819ee96
fix snake naming bug
vivekvenkris Sep 23, 2024
63b85f8
actually fix snake naming bug
vivekvenkris Sep 23, 2024
510fc01
use long double for times, incorporate downstream changes for half ch…
vivekvenkris Sep 25, 2024
4ae82ab
fixed formatting on MultiFileWriter.cuh
Sep 26, 2024
2787d00
formatting
Sep 26, 2024
6a33108
Add .tmp suffix to output filenames, and remove it when they are closed.
coclar Sep 26, 2024
bbd9fd1
Merge pull request #21 from hefehr/temporary_filenames
ewanbarr Sep 27, 2024
456719a
cleave only required samples
vivekvenkris Sep 30, 2024
48adc14
cleave only required dms and beams, code review changes
vivekvenkris Oct 2, 2024
0cfe1f9
seek to start sample after dedisp delay correction
vivekvenkris Oct 3, 2024
ee35ae2
CDD all data including overlap
vivekvenkris Oct 3, 2024
52b1ab3
fix FFT shift, change left over gulps -> fft_size where appropriate
vivekvenkris Oct 7, 2024
4bf4df1
Make skycleaver a CPP application
vivekvenkris Oct 11, 2024
70647a9
correctly set frequencies for described vectors, CDD, IDD
vivekvenkris Oct 11, 2024
0dde728
Added multiple tiling plot code, targets file, mosaic command file, p…
vishnubk Oct 21, 2024
5ca8add
removed unused class
vishnubk Oct 21, 2024
8fbb204
changed python delay creation code to plot, even if no known beams ar…
vishnubk Nov 6, 2024
0595fa9
Remove .bdm.db files and update .gitignore
vishnubk Nov 6, 2024
00fa137
typo fixes in include flags, migration from cuh to hpp
vishnubk Nov 6, 2024
e697b31
minor merge changes
vivekvenkris Nov 25, 2024
a1a2c94
get header values from header instead of user
vivekvenkris Nov 26, 2024
cbaf03b
dirty pass on scaling change
Nov 28, 2024
820efb9
compiling now and beamformer tests running
Nov 28, 2024
49c966a
linear pol output and actual beam positions in skycleaver
vivekvenkris Dec 12, 2024
ff71497
fix filename convention
vivekvenkris Dec 12, 2024
45964ca
draft documentation
vivekvenkris Dec 17, 2024
8610cab
Revert "compiling now and beamformer tests running"
vivekvenkris Dec 22, 2024
112a857
Revert "dirty pass on scaling change"
vivekvenkris Dec 22, 2024
13047bb
segregate filterbanks in beam directories
vivekvenkris Jan 2, 2025
4f15b64
Fix for incorrect S-band frequencies being reported in filenames due …
coclar Jan 29, 2025
fbb980b
Merge pull request #24 from hefehr/filename_freq_fix
ewanbarr Jan 29, 2025
03b92c5
Fix for integer overflow in SkyCleaver while computing expected bridg…
coclar Feb 13, 2025
4242cf9
Added command-line option for computing/outputing voltage statistics
coclar Feb 20, 2025
6675ae6
Added command-line option to disable writing the incoherent beam
coclar Feb 20, 2025
ab6b13e
Merge pull request #26 from hefehr/optional_outputs
ewanbarr Mar 5, 2025
0d8e6aa
Merge pull request #25 from hefehr/skycleaver_freq_fix
ewanbarr Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ eggs/
core*
report*
CMakeCache.txt
.nextflow
*.bdm.db

4 changes: 2 additions & 2 deletions Dockerfile.skyweavercpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ WORKDIR /usr/src/skyweaver
COPY . .
RUN cmake -S . -B build/ -DARCH=native -DPSRDADA_INCLUDE_DIR=/usr/local/include/psrdada \
-DPSRDADACPP_INCLUDE_DIR=/usr/local/include/psrdada_cpp -DSKYWEAVER_NANTENNAS=64 \
-DSKYWEAVER_NBEAMS=128 -DSKYWEAVER_NCHANS=64 -DSKYWEAVER_IB_SUBTRACTION=1 -DBUILD_SUBMODULES=1 \
-DENABLE_TESTING=1 -DENABLE_BENCHMARK=1 &&\
-DSKYWEAVER_NBEAMS=800 -DSKYWEAVER_NCHANS=64 -DSKYWEAVER_IB_SUBTRACTION=1 -DBUILD_SUBMODULES=1 \
-DENABLE_TESTING=1 -DENABLE_BENCHMARK=1 -DSKYWEAVER_CB_TSCRUNCH=4 -DSKYWEAVER_IB_TSCRUNCH=4 -DSKYWEAVER_CB_FSCRUNCH=1 -DSKYWEAVER_IB_FSCRUNCH=1 &&\
make -C build/ -j 16 && make -C build/ install

3 changes: 2 additions & 1 deletion Dockerfile.skyweaverpy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ RUN apt-get update && apt-get install -y \

# Install Python dependencies
RUN pip install --upgrade pip && \
pip install pytest
pip install pytest && \
pip install pandas


# Copy the rest of your application code into the container
Expand Down
175 changes: 175 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,177 @@
# skyweaver
Implementation of an offline FBFUSE beamformer for the MeerKAT telescope

# Installation

It is easiest to use the software inside a Docker container. Two dockerfiles is included part of this repository: To compile the c++ and python parts respectively.

# Usage

## Step 1: Get delays for the beamformer

### Start with the skyweaver python CLI

```bash
alias sw="python /path/to/python/skyweaver/cli.py"
sw --help
```
This will print:
```console
usage: skyweaver [-h] {metadata,delays} ...

positional arguments:
{metadata,delays} sub-command help
metadata Tools for observation metadata files
delays Tools for delay files

optional arguments:
-h, --help show this help message and exit
```

### Get the metadata for the corresponding observation

This is done outside this repository

### Obtain metadata information

```bash
sw metadata show <metadata_file>
```

This will produce an output like the following:
```console
sw metadata show bvrmetadata_2024-02-16T10\:50\:46_72275.hdf5
---------------Array configuration----------------
Nantennas: 57
Subarray: m000,m002,m003,m004,m005,m007,m008,m009,m010,m011,m012,m014,m015,m016,
m017,m018,m019,m020,m021,m022,m023,m024,m025,m026,m027,m029,m030,m031,
m032,m033,m034,m035,m036,m037,m038,m039,m040,m041,m042,m043,m044,m045,
m046,m048,m049,m050,m051,m053,m054,m056,m057,m058,m059,m060,m061,m062,
m063
Centre frequency: 1284000000.0 Hz
Bandwidth: 856000000.0 Hz
Nchannels: 4096
Sync epoch (UNIX): 1708039531.0
Project ID: -
Schedule block ID: -
CBF version: cbf_dev
--------------------Pointings---------------------
#0 J1644-4559 2024-02-16T11:16:08.957000000 until 2024-02-16T11:21:04.865000000 (UTC)
1708082168.957 until 1708082464.865 (UNIX)
72996182384029 until 73502776880016 (SAMPLE CLOCK)
#1 J1644-4559_Offset1 2024-02-16T11:21:22.092000000 until 2024-02-16T11:26:15.682000000 (UTC)
1708082482.092 until 1708082775.682 (UNIX)
73532269504013 until 74034895583866 (SAMPLE CLOCK)
#2 J1644-4559_Offset2 2024-02-16T11:26:34.536000000 until 2024-02-16T11:31:25.723000000 (UTC)
1708082794.536 until 1708083085.723 (UNIX)
74067173632022 until 74565685776084 (SAMPLE CLOCK)
#3 M28 2024-02-16T11:31:52.503000000 until 2024-02-16T12:01:51.651000000 (UTC)
1708083112.503 until 1708084911.651 (UNIX)
74611533136035 until 77691674512039 (SAMPLE CLOCK)
#4 J0437-4715 2024-02-16T12:03:06.117000000 until 2024-02-16T12:08:04.364000000 (UTC)
1708084986.117 until 1708085284.364 (UNIX)
77819160304176 until 78329759168140 (SAMPLE CLOCK)
```

### Create a config file in .yml format
Here is an example - there are comments to explain each parameter.

```.yml
created_by: Vivek
beamformer_config:
# The total number of beams to be produced (must be a multiple of 32). This needs to be <= the number that SKYWEAVER is compiled for.
total_nbeams: 800
# The number of time samples that will be accumulated after detection, inside the beamformer
tscrunch: 4
# The number of frequency channels that will be accumulated after detection, inside the beamformer
# Will be coerced to 1 if coherent dedispersion is specified.
fscrunch: 1
# The Stokes product to be calculated in the beamformer (I=0, Q=1, U=2, V=3)
stokes_mode: 0
# Enable CB-IB subtraction in the beamformer
subtract_ib: True

# Dispersion measure for coherent / incoherent dedispersion in pc cm^-3
# A dispersion plan definition string "
# "(<coherent_dm>:<start_incoherent_dm>:<end_incoherent_dm>:<dm_step>:<tscrunch>) or "
# "(<coherent_dm>:<tscrunch>) "
# "or (<coherent_dm>)")
# Each DD plan is a "Stream" with zero indexed stream-ids

ddplan:
- "478.6:478.6:478.6:1:1" #stream-id=0
- "0.00:478.6:478.6:1:1" #stream-id=1

# every beamset can contain arbitrary set of antennas, corresponding targeted beams, and tiled beams
# total number of beams across all beamsets should be <= the number of beams that SKYWEAVER is compiled for.
beam_sets:

- antenna_set: ['m000','m002','m003','m004','m005','m007','m008','m009','m010','m011',
'm012','m014','m015','m016','m017','m018','m019','m020','m021','m022',
'm023','m024','m025','m026','m027','m029','m030','m031','m032','m033',
'm034','m035','m036','m037','m038','m039','m040','m041','m042','m043',
'm044','m045','m046','m048','m049','m050','m051','m053','m054','m056',
'm057','m058','m059','m060','m061','m062','m063']
beams: []
tilings:
- nbeams: 32
reference_frequency: null
target: "J1644-4559,radec,16:44:49.273,-45:59:09.71"
overlap: 0.9
```



### Create delay file for the corresponding pointing

```bash
sw delays create --pointing-idx 0 --outfile J1644-4559_pointing_0.delays --step 4 bvrmetadata_2024-02-16T10\:50\:46_72275.hdf5 J1644-4559_boresight.yaml
```

This produces a `.delays` file used for beamforming, and a `.targets` file that contains beam metadata. There are also other files produced here for reproducibility and for visualisation.

## Step 2: Initialise input and compile skyweaver

### Create a list of dada files that correspond to the pointing

```console
ls /b/u/vivek/00_DADA_FILES/J1644-4559/2024-02-16-11\:16\:08/L/48/*dada -1 > /bscratch/vivek/skyweaver_tests/J1644-4559_boresight_dadafiles.list
```

### Compile skyweaver

This is done inside the dockerfile too. Either edit that to produce a docker image that has the software precompiled, or compile separately.

```bash
cmake -S . -B $cmake_tmp_dir -DENABLE_TESTING=0 -DCMAKE_INSTALL_PREFIX=$install_dir -DARCH=native -DPSRDADA_INCLUDE_DIR=/usr/local/include/psrdada -DPSRDADACPP_INCLUDE_DIR=/usr/local/include/psrdada_cpp -DSKYWEAVER_NANTENNAS=64 -DSKYWEAVER_NBEAMS=${nbeams} -DSKYWEAVER_NCHANS=64 -DSKYWEAVER_IB_SUBTRACTION=1 -DCMAKE_BUILD_TYPE=RELEASE -DSKYWEAVER_CB_TSCRUNCH=${tscrunch} -DSKYWEAVER_IB_TSCRUNCH=${tscrunch};
cd $cmake_tmp_dir
make -j 16
```
This compilation produces two binaries: `skyweavercpp` and `skycleaver`
## Step 3: Run the beamformer

```bash

/path/to/skyweavercpp --input-file J1644-4559_boresight_dadafiles.list --delay-file J1644-4559_pointing_0.delays --output-dir=/bscratch/vivek/skyweaver_out --gulp-size=32768 --log-level=warning --output-level=12 --stokes-mode I
```

Change the output level to 7 for bright pulsars like J1644-4559.

This will produce `.tdb` files for the corresponding bridge. Run Step 3 for ALL 64 bridges with their corresponding dada file lists. These are DADA format files with the dimensions of TIME, INCOHERENT DM and BEAM as the order. For stokes I mode, The datatype is `int8_t`. For IQUV it is `char4`.

## Steo 4: Cleave all bridges to form Filterbanks

Here we cleave the 64 TDB[I/Q/U/V/IV/QU/IQUV] files to produce `NDM*NBEAMS*NSTOKES` number of T(F=64) files.

to run this, do

```bash

/path/to/skycleaver -r /bscratch/vivek/skyweaver_out --output-dir /bscratch/vivek/skycleaver_out --nsamples-per-block 65536 --nthreads 32 --stream-id 0 --targets_file/bscratch/vivek/skyweaver_out/swdlays_J1644-4559.targets --out-stokes I --required_beams 0

```

This will produce a standard sigproc format `.fil` file that can be used for traditional processing.



2 changes: 2 additions & 0 deletions cmake/compiler_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RELEASE")
endif ()

#set(CMAKE_VERBOSE_MAKEFILE 1)
set (CMAKE_CXX_STANDARD 20)
# Set compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fopenmp")

Expand Down
15 changes: 14 additions & 1 deletion cpp/skyweaver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(skyweaver_src
src/Timer.cpp
src/Transposer.cu
src/WeightsManager.cu
src/SigprocHeader.cpp

)

set(skyweaver_inc
Expand All @@ -38,6 +40,10 @@ set(skyweaver_inc
Timer.hpp
Transposer.cuh
WeightsManager.cuh
MultiFileWriter.cuh
SigprocHeader.hpp
SkyCleaver.hpp
SkyCleaverConfig.hpp
)

set(SKYWEAVER_LIBRARIES ${CMAKE_PROJECT_NAME} ${DEPENDENCY_LIBRARIES})
Expand Down Expand Up @@ -106,6 +112,13 @@ target_link_libraries(skyweavercpp
OpenMP::OpenMP_CXX)
install(TARGETS skyweavercpp DESTINATION bin)

add_executable(skycleaver src/skycleaver_cli.cpp)
target_link_libraries(skycleaver
${SKYWEAVER_LIBRARIES}
${DEPENDENCY_LIBRARIES}
OpenMP::OpenMP_CXX)
install(TARGETS skycleaver DESTINATION bin)

#install (TARGETS ... DESTINATION bin)
#install (TARGETS ${CMAKE_PROJECT_NAME}
# RUNTIME DESTINATION bin
Expand All @@ -126,4 +139,4 @@ if(ENABLE_BENCHMARK)
COMMAND beamformer_bench --benchmark_counters_tabular=true
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(benchmark)
endif()
endif()
42 changes: 40 additions & 2 deletions cpp/skyweaver/DescribedVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ struct DescribedVector {
_vector.resize(calculate_nelements());
}

/**
* @brief Construct a new Described Vector object of specific size
*
* @param sizes The sizes of the dimensions (must match the number of
* dimensions)
*/
DescribedVector(std::initializer_list<std::size_t> sizes, value_type default_value)
: _dms_stale(true), _frequencies_stale(true), _sizes(sizes),
_dims{dims...}, _tsamp(0.0)
{
if(_sizes.size() != sizeof...(dims)) {
throw std::invalid_argument(
"Number of sizes must match number of dimensions");
}
_vector.resize(calculate_nelements(), default_value);
}

/**
* @brief Destroy the Described Vector object
*
Expand Down Expand Up @@ -213,6 +230,12 @@ struct DescribedVector {
*/
auto const& operator[](std::size_t idx) const { return _vector[idx]; }


// also the at() method
auto& at(std::size_t idx) { return _vector[idx]; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose does this serve?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is another function in std::vector that I tried to mimic here. Not required but good to have.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, we decided to keep this in.

auto const& at(std::size_t idx) const { return _vector[idx]; }


/**
* @brief Resize the dimensions of the vector
*
Expand Down Expand Up @@ -343,12 +366,13 @@ struct DescribedVector {
* @param freqs
*/
void frequencies(FrequenciesType const& freqs)
{
{
if(freqs.size() != get_dim_extent<FreqDim>()) {
throw std::runtime_error("Invalid number of frequecies passed.");
}
_frequencies_stale = false;
_frequencies = freqs;

}

/**
Expand All @@ -363,6 +387,7 @@ struct DescribedVector {
}
_frequencies_stale = false;
_frequencies.resize(1, freq);
_frequencies[0] = freq;
}

/**
Expand Down Expand Up @@ -648,7 +673,7 @@ using BTFPowersH = DescribedVector<thrust::host_vector<T, PinnedAllocator<T>>,
template <typename T>
using BTFPowersD =
DescribedVector<thrust::device_vector<T>, BeamDim, TimeDim, FreqDim>;
// Incoherent dedisperser outputs
// Incoherent dedisperser outputs, also used for skycleaver
template <typename T>
using TDBPowersH = DescribedVector<thrust::host_vector<T, PinnedAllocator<T>>,
TimeDim,
Expand All @@ -667,6 +692,19 @@ template <typename T>
using FPAStatsD =
DescribedVector<thrust::device_vector<T>, FreqDim, PolnDim, AntennaDim>;


//skycleaver vectors
template <typename T>
using TDBPowersStdH = DescribedVector<std::vector<T>,
TimeDim,
DispersionDim,
BeamDim,
PolnDim>;
template <typename T>
using TFPowersStdH = DescribedVector<std::vector<T>,
TimeDim,
FreqDim>;

} // namespace skyweaver

#endif // SKYWEAVER_DESCRIBEDVECTORS_HPP
2 changes: 2 additions & 0 deletions cpp/skyweaver/FileOutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class FileOutputStream
std::string _full_path;
std::size_t _bytes_requested;
std::size_t _bytes_written;
std::string _temporary_suffix;
std::string _temporary_path;
std::ofstream _stream;
};

Expand Down
21 changes: 21 additions & 0 deletions cpp/skyweaver/Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ class Header
template <typename T>
T get(char const* key) const;


/**
* @brief Get a value from the header or return a default value
*
* @param key An ASCII key (the name of the value to get)
* @param[in] default_value The default value to return if the key is not found
*
* @tparam T The data type of the parameter to be read
*
* @return The value corresponding to the given key or the default value
*/
template <typename T>
T get_or_default(char const* key, T default_value) const{
if(has_key(key)){
return get<T>(key);
}
BOOST_LOG_TRIVIAL(warning) << "Header did not have key: " << key << ". Returning default value: " << default_value;
return default_value;
}

/**
* @brief Set a value in the header
*
Expand Down Expand Up @@ -72,6 +92,7 @@ class Header

private:
void fetch_header_string(char const* key) const;
bool has_key(char const* key) const;

private:
psrdada_cpp::RawBytes& _header;
Expand Down
Loading