Skip to content

Commit

Permalink
Merge pull request kotekan#912 from kotekan/develop
Browse files Browse the repository at this point in the history
Merge develop to master for 2020.11a release
  • Loading branch information
andrerenard authored Dec 3, 2020
2 parents e85e385 + eb8e03d commit f366ab1
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 58 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ option(SUPERDEBUG "Enable extra debugging with no optimisation" OFF)
option(SANITIZE "Enable clang sanitizers for testing" OFF)
option(COMPILE_DOCS "Use Sphinx to compile documentation" OFF)
option(WITH_TESTS "Compile testing library and boost C++ unit tests" OFF)
option(_GOSSEC "Set buffer status messages to DEBUG log level" OFF)
option(IWYU "Enable include-what-you-use and print suggestions to stderr" OFF)
option(CCACHE "Use ccache to speed up the build" OFF)
option(WERROR "Warnings are errors" OFF)
Expand Down Expand Up @@ -100,11 +99,6 @@ if(${SANITIZE})
"${CMAKE_CXX_FLAGS_DEBUG} -fno-optimize-sibling-calls -fsanitize=address")
endif()

if(${_GOSSEC})
add_definitions(-D_GOSSEC=1)
message("_GOSSEC enabled: Set buffer status messages to DEBUG log level")
endif()

if(${USE_HCC} AND (CMAKE_CXX_COMPILER MATCHES ".*hcc"))
find_package(HCC)
set(USE_HCC ${HCC_fOUND})
Expand Down
16 changes: 8 additions & 8 deletions config/chime_science_run_gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ updatable_config:
# These inputs are assumed to be in cylinder order
bad_inputs: [ 46, 84, 107, 136, 142, 256, 257, 319, 348, 357, 369,
370, 453, 550, 551, 579, 638, 688, 739, 742, 768, 784,
807, 855, 944, 960, 971, 981, 986, 1005, 1010, 1020, 1023,
1058, 1141, 1166, 1225, 1280, 1281, 1285, 1314, 1343, 1380, 1381,
1521, 1523, 1543, 1642, 1687, 1738, 1792, 1794, 1910, 1912, 1943,
1945, 1950, 1982, 1984, 1987, 2032, 2034]
807, 855, 944, 960, 967, 971, 981, 986, 1005, 1010, 1020,
1023, 1058, 1141, 1166, 1225, 1280, 1281, 1285, 1311, 1314, 1343,
1380, 1381, 1479, 1521, 1523, 1543, 1642, 1684, 1687, 1738, 1792,
1794, 1910, 1912, 1943, 1945, 1950, 1982, 1984, 1987, 2032, 2034]

start_time: 1535048997.
update_id: "initial_flags"
Expand Down Expand Up @@ -1665,10 +1665,10 @@ eigcalc:
bands_filled: [ [0, 30], [251, 262] ]
exclude_inputs: [ 46, 84, 107, 136, 142, 256, 257, 319, 348, 357, 369,
370, 453, 550, 551, 579, 638, 688, 739, 742, 768, 784,
807, 855, 944, 960, 971, 981, 986, 1005, 1010, 1020, 1023,
1058, 1141, 1166, 1225, 1280, 1281, 1285, 1314, 1343, 1380, 1381,
1521, 1523, 1543, 1642, 1687, 1738, 1792, 1794, 1910, 1912, 1943,
1945, 1950, 1982, 1984, 1987, 2032, 2034]
807, 855, 944, 960, 967, 971, 981, 986, 1005, 1010, 1020,
1023, 1058, 1141, 1166, 1225, 1280, 1281, 1285, 1311, 1314, 1343,
1380, 1381, 1479, 1521, 1523, 1543, 1642, 1684, 1687, 1738, 1792,
1794, 1910, 1912, 1943, 1945, 1950, 1982, 1984, 1987, 2032, 2034]

vis_debug:
kotekan_stage: visDebug
Expand Down
16 changes: 8 additions & 8 deletions config/chime_science_run_gpu_no_output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ updatable_config:
# These inputs are assumed to be in cylinder order
bad_inputs: [ 46, 84, 107, 136, 142, 256, 257, 319, 348, 357, 369,
370, 453, 550, 551, 579, 638, 688, 739, 742, 768, 784,
807, 855, 944, 960, 971, 981, 986, 1005, 1010, 1020, 1023,
1058, 1141, 1166, 1225, 1280, 1281, 1285, 1314, 1343, 1380, 1381,
1521, 1523, 1543, 1642, 1687, 1738, 1792, 1794, 1910, 1912, 1943,
1945, 1950, 1982, 1984, 1987, 2032, 2034]
807, 855, 944, 960, 967, 971, 981, 986, 1005, 1010, 1020,
1023, 1058, 1141, 1166, 1225, 1280, 1281, 1285, 1311, 1314, 1343,
1380, 1381, 1479, 1521, 1523, 1543, 1642, 1684, 1687, 1738, 1792,
1794, 1910, 1912, 1943, 1945, 1950, 1982, 1984, 1987, 2032, 2034]
start_time: 1535048997.
update_id: "initial_flags"
rfi_zeroing_toggle:
Expand Down Expand Up @@ -1664,10 +1664,10 @@ eigcalc:
bands_filled: [ [0, 30], [251, 262] ]
exclude_inputs: [ 46, 84, 107, 136, 142, 256, 257, 319, 348, 357, 369,
370, 453, 550, 551, 579, 638, 688, 739, 742, 768, 784,
807, 855, 944, 960, 971, 981, 986, 1005, 1010, 1020, 1023,
1058, 1141, 1166, 1225, 1280, 1281, 1285, 1314, 1343, 1380, 1381,
1521, 1523, 1543, 1642, 1687, 1738, 1792, 1794, 1910, 1912, 1943,
1945, 1950, 1982, 1984, 1987, 2032, 2034]
807, 855, 944, 960, 967, 971, 981, 986, 1005, 1010, 1020,
1023, 1058, 1141, 1166, 1225, 1280, 1281, 1285, 1311, 1314, 1343,
1380, 1381, 1479, 1521, 1523, 1543, 1642, 1684, 1687, 1738, 1792,
1794, 1910, 1912, 1943, 1945, 1950, 1982, 1984, 1987, 2032, 2034]

vis_debug:
kotekan_stage: visDebug
Expand Down
17 changes: 12 additions & 5 deletions config/chime_science_run_recv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ vis_buffer:
visbuf_10s_gain:
kotekan_buffer: vis
buffer_depth: 384 # Before slow stage
visbuf_10s_rf:
kotekan_buffer: vis
visbuf_10s_flags:
kotekan_buffer: vis
buffer_depth: 4096 # Before slow stage
Expand Down Expand Up @@ -133,10 +135,10 @@ updatable_config:
update_id: "initial_flags"
bad_inputs: [ 46, 84, 107, 136, 142, 256, 257, 319, 348, 357, 369,
370, 453, 550, 551, 579, 638, 688, 739, 742, 768, 784,
807, 855, 944, 960, 971, 981, 986, 1005, 1010, 1020, 1023,
1058, 1166, 1225, 1280, 1281, 1285, 1314, 1343, 1380, 1381, 1521,
1523, 1543, 1642, 1687, 1738, 1792, 1794, 1910, 1912, 1943, 1945,
1950, 1982, 1984, 1987, 2032, 2034]
807, 855, 944, 960, 967, 971, 981, 986, 1005, 1010, 1020,
1023, 1058, 1141, 1166, 1225, 1280, 1281, 1285, 1311, 1314, 1343,
1380, 1381, 1479, 1521, 1523, 1543, 1642, 1684, 1687, 1738, 1792,
1794, 1910, 1912, 1943, 1945, 1950, 1982, 1984, 1987, 2032, 2034]
gains:
kotekan_update_endpoint: "json"
start_time: 1575950518.4
Expand Down Expand Up @@ -185,10 +187,15 @@ switch_26m_gated:
receive_flags:
kotekan_stage: ReceiveFlags
in_buf: visbuf_10s_all
out_buf: visbuf_10s_flags
out_buf: visbuf_10s_rf
updatable_config: "/updatable_config/flagging"
num_kept_updates: 24

bad_inputs_check:
kotekan_stage: BadInputFlag
in_buf: visbuf_10s_rf
out_buf: visbuf_10s_flags

vis_debug:
n2:
kotekan_stage: visDebug
Expand Down
9 changes: 3 additions & 6 deletions lib/core/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,10 @@ uint8_t* wait_for_empty_frame(struct Buffer* buf, const char* producer_name, con

CHECK_ERROR_F(pthread_mutex_unlock(&buf->lock));

// TODO: temporary solution to not print buffer status on gossec
#ifndef _GOSSEC
if (print_stat == 1)
print_buffer_status(buf);
#else
// TODO: remove this output until we have a solution which has better control over log levels
// if (print_stat == 1)
// print_buffer_status(buf);
(void)print_stat;
#endif

if (buf->shutdown_signal == 1)
return NULL;
Expand Down
20 changes: 15 additions & 5 deletions lib/core/prometheusMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#include "kotekanLogging.hpp" // for ERROR_NON_OO
#include "restServer.hpp" // for restServer, connectionInstance

#include "fmt.hpp" // for format, fmt, print
#include "fmt.hpp" // for print, format, fmt

#include <functional> // for _Bind_helper<>::type, _Placeholder, bind, _1
#include <cmath> // for isinf, isnan
#include <functional> // for _Bind_helper<>::type, _Placeholder, bind, _1, placeholders
#include <iterator> // for begin, end
#include <ostream> // for operator<<, ostringstream, basic_ostream
#include <ostream> // for operator<<, basic_ostream
#include <sys/time.h> // for gettimeofday, timeval
#include <utility> // for pair

Expand Down Expand Up @@ -55,13 +56,22 @@ void Gauge::set(const double value) {
}

string Gauge::to_string() {
return fmt::format(fmt("{:f} {:d}"), value, last_update_time_stamp);
std::ostringstream buf;
to_string(buf);
return buf.str();
}

std::ostringstream& Gauge::to_string(std::ostringstream& out) {
std::lock_guard<std::mutex> lock(metric_lock);

fmt::print(out, fmt("{:f} {:d}"), value, last_update_time_stamp);
if (std::isnan(value)) {
fmt::print(out, fmt("NaN {:d}"), last_update_time_stamp);
} else if (std::isinf(value)) {
fmt::print(out, fmt("{} {:d}"), (value < 0 ? "-Inf" : "+Inf"), last_update_time_stamp);
} else {
fmt::print(out, fmt("{:f} {:d}"), value, last_update_time_stamp);
}

return out;
}

Expand Down
136 changes: 136 additions & 0 deletions lib/stages/BadInputFlag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "BadInputFlag.hpp"

#include "Config.hpp" // for Config
#include "Hash.hpp" // for operator!=, operator==, Hash, operator<
#include "StageFactory.hpp" // for REGISTER_KOTEKAN_STAGE, StageMakerTemplate
#include "buffer.h" // for mark_frame_empty, mark_frame_full, register_consumer
#include "bufferContainer.hpp" // for bufferContainer
#include "datasetManager.hpp" // for dset_id_t, datasetManager, fingerprint_t
#include "kotekanLogging.hpp" // for FATAL_ERROR
#include "prometheusMetrics.hpp" // for Counter, MetricFamily, Metrics
#include "visBuffer.hpp" // for VisFrameView
#include "visUtil.hpp" // for frameID, modulo

#include "gsl-lite.hpp" // for span

#include <algorithm> // for copy, copy_backward, equal, max
#include <assert.h> // for assert
#include <atomic> // for atomic_bool
#include <cmath> // for isinf, isnan
#include <deque> // for deque
#include <functional> // for _Bind_helper<>::type, bind, function
#include <future> // for future
#include <optional> // for optional
#include <stddef.h> // for size_t


using kotekan::bufferContainer;
using kotekan::Config;
using kotekan::Stage;
using kotekan::prometheus::Metrics;

REGISTER_KOTEKAN_STAGE(BadInputFlag);

BadInputFlag::BadInputFlag(Config& config, const std::string& unique_name,
bufferContainer& buffer_container) :
Stage(config, unique_name, buffer_container, std::bind(&BadInputFlag::main_thread, this)),
bad_input_counter(Metrics::instance().add_counter("kotekan_badinputflag_frames_total",
unique_name, {"input_id", "type"})) {

// Get buffers
in_buf = get_buffer("in_buf");
register_consumer(in_buf, unique_name.c_str());
out_buf = get_buffer("out_buf");
register_producer(out_buf, unique_name.c_str());
}

void BadInputFlag::check_dataset_state(dset_id_t ds_id) {

auto& dm = datasetManager::instance();

// If any of these states have changed the interpretation of the vis/weight elements
// will have changed, in that case we need to exit as things will end up being
// inconsistent
// TODO: this limitation could be fixed by doing a bunch of work interpreting the
// products and matching up to specific inputs, but that's for another time
auto fprint = dm.fingerprint(ds_id, {"inputs", "products", "stack"});
if (fingerprint == fingerprint_t::null) {

// Check that this is not a stacked dataset, if it is we can't look at
// individual autocorrelations and so this stage won't work
if (dm.closest_dataset_of_type(ds_id, "stack")) {
FATAL_ERROR("This dataset {} has a stackState, but we need the full triangle.", ds_id);
}

fingerprint = fprint;
}

if (fprint != fingerprint) {
FATAL_ERROR("This dataset {} has a different fingerprint {} from expected.", ds_id, fprint,
fingerprint);
}

dset_id_set.insert(ds_id);
}

void BadInputFlag::main_thread() {


frameID input_frame_id(in_buf);
frameID output_frame_id(out_buf);

std::future<void> change_dset_fut;

while (!stop_thread) {

// Wait for the input buffer to be filled with data
if (wait_for_full_frame(in_buf, unique_name.c_str(), input_frame_id) == nullptr) {
break;
}

// Wait for the output buffer frame to be free
if (wait_for_empty_frame(out_buf, unique_name.c_str(), output_frame_id) == nullptr) {
break;
}

// Get a view of the current frame
auto frame = VisFrameView::copy_frame(in_buf, input_frame_id, out_buf, output_frame_id);

// check if the input dataset has changed
if (dset_id_set.count(frame.dataset_id) == 0) {
check_dataset_state(frame.dataset_id);
}

size_t num_elements = frame.num_elements;
size_t num_prod = frame.num_prod;

assert(num_prod == num_elements * (num_elements + 1) / 2);

// Iterate over autocorrelations
size_t auto_ind = 0;
for (size_t i = 0; i < num_elements; i++) {

// If the input is listed as valid, check to see if the corresponding
// weights are bad (i.e. infinite or NaN). If so, flag the input and export
// it to Prometheus
if (frame.flags[i] != 0) {
if (std::isinf(frame.weight[auto_ind])) {
bad_input_counter.labels({std::to_string(i), "Inf"}).inc();
// TODO: post dataset state changes and turn this on
// frame.flags[i] = 0;

} else if (std::isnan(frame.weight[auto_ind])) {
bad_input_counter.labels({std::to_string(i), "NaN"}).inc();
// TODO: post dataset state changes and turn this on
// frame.flags[i] = 0;
}
}

auto_ind += (num_elements - i);
}

// Mark the buffers and move on
mark_frame_full(out_buf, unique_name.c_str(), output_frame_id++);
mark_frame_empty(in_buf, unique_name.c_str(), input_frame_id++);
}
}
73 changes: 73 additions & 0 deletions lib/stages/BadInputFlag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*****************************************
@file
@brief Check a frame for bad inputs.
- BadInputFlag : public kotekan::Stage
*****************************************/
#ifndef BAD_INPUT_FLAG_HPP
#define BAD_INPUT_FLAG_HPP

#include "Config.hpp" // for Config
#include "Stage.hpp" // for Stage
#include "buffer.h" // for Buffer
#include "bufferContainer.hpp" // for bufferContainer
#include "datasetManager.hpp" // for dset_id_t, fingerprint_t
#include "prometheusMetrics.hpp" // for Counter, MetricFamily

#include <set> // for set
#include <string> // for string


/**
* @class BadInputFlag
* @brief searches for bad inputs that aren't marked in the `flags` field.
*
* @par Buffers
* @buffer in_buf The buffer from which the visibilities are checked, must be a full triangle.
* @buffer_format VisBuffer structured
* @buffer_metadata VisMetadata
* @buffer out_buf The kotekan buffer which will be fed the output.
* @buffer_format VisBuffer structured
* @buffer_metadata VisMetadata
*
* @par Metrics
* @metric kotekan_badinputflag_frames_total
* The number of frames found with unmarked bad inputs. The metrics are labelled with
* which `input` is bad, and why (Infinite weight, NaN weight).
*
* @warning This will only work correctly if the full correlation triangle is
* passed in as input.
*
* @author Richard Shaw
*
*/
class BadInputFlag : public kotekan::Stage {

public:
/// Constructor. Loads config options. Defines subset of products.
BadInputFlag(kotekan::Config& config, const std::string& unique_name,
kotekan::bufferContainer& buffer_container);

/// Primary loop: sorts products and passes them on to output buffer.
void main_thread() override;

private:
/// keeps track of the input dataset ID and ensures the products haven't changed
void check_dataset_state(dset_id_t ds_id);

/// Input buffer
Buffer* in_buf;

/// Output buffer to receive baseline subset visibilities
Buffer* out_buf;

// Maps for determining the dataset ID to use
std::set<dset_id_t> dset_id_set;

fingerprint_t fingerprint = fingerprint_t::null;

// Count how often a bad input has been seen
kotekan::prometheus::MetricFamily<kotekan::prometheus::Counter>& bad_input_counter;
};


#endif
3 changes: 2 additions & 1 deletion lib/stages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ add_library(
BeamExtract.cpp
BeamInspect.cpp
testDataGen.cpp
DPDKShuffleSimulate.cpp)
DPDKShuffleSimulate.cpp
BadInputFlag.cpp)

target_include_directories(kotekan_stages PRIVATE .)

Expand Down
Loading

0 comments on commit f366ab1

Please sign in to comment.