-
Notifications
You must be signed in to change notification settings - Fork 18
Update verbose logging mechanism to enable callback provided by user #67
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3f7c309
Merge pull request #26 from quantumlib/main
noajshu 93a96a8
Merge remote-tracking branch 'quantum/main'
noajshu e693307
Merge remote-tracking branch 'quantum'
noajshu f57496c
Merge pull request #29 from quantumlib/main
noajshu 9776627
Expose detector order creation
noajshu fb2f13b
Merge pull request #30 from noajshu/codex/refactor-det-order-creation…
noajshu f9ef348
Merge branch 'main' into main
noajshu b950ae0
Make init_ilp private and drop binding
noajshu eb93a84
Merge pull request #31 from noajshu/codex/make-init_ilp-method-private
noajshu eab2062
Add CMake build system
noajshu 1de3cad
Merge pull request #32 from noajshu/codex/add-cmake-support-for-tesse…
noajshu d4d0040
refactor: remove verbose flag in favor of log stream
noajshu 260799e
Merge pull request #33 from noajshu/codex/refactor-tesseractconfig-an…
noajshu 7609132
Merge remote-tracking branch 'origin'
noajshu b59be9e
fix the logging of highs
noajshu 36995a9
Merge branch 'main' into main
noajshu 8d32504
ran clang-format -i src/*.cc src/*.h
noajshu 0f7b56c
Merge remote-tracking branch 'origin'
noajshu 0995f46
undo change to import path
noajshu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| cmake_minimum_required(VERSION 3.16) | ||
| project(tesseract_decoder LANGUAGES CXX) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 20) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| include(FetchContent) | ||
| find_package(Threads REQUIRED) | ||
|
|
||
| # === External dependencies === | ||
| # Stim | ||
| FetchContent_Declare( | ||
| stim | ||
| GIT_REPOSITORY https://github.com/quantumlib/stim.git | ||
| GIT_TAG bd60b73525fd5a9b30839020eb7554ad369e4337 | ||
| ) | ||
| FetchContent_MakeAvailable(stim) | ||
|
|
||
| # HiGHS | ||
| FetchContent_Declare( | ||
| highs | ||
| URL https://github.com/ERGO-Code/HiGHS/archive/refs/tags/v1.9.0.tar.gz | ||
| URL_HASH SHA256=dff575df08d88583c109702c7c5c75ff6e51611e6eacca8b5b3fdfba8ecc2cb4 | ||
| ) | ||
| FetchContent_MakeAvailable(highs) | ||
|
|
||
| # argparse (header only) | ||
| FetchContent_Declare( | ||
| argparse | ||
| URL https://github.com/p-ranav/argparse/archive/refs/tags/v3.1.zip | ||
| URL_HASH SHA256=3e5a59ab7688dcd1f918bc92051a10564113d4f36c3bbed3ef596c25e519a062 | ||
| ) | ||
| FetchContent_MakeAvailable(argparse) | ||
|
|
||
| # nlohmann_json (header only) | ||
| FetchContent_Declare( | ||
| nlohmann_json | ||
| URL https://github.com/nlohmann/json/archive/9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03.zip | ||
| ) | ||
| FetchContent_MakeAvailable(nlohmann_json) | ||
|
|
||
| # Boost headers | ||
| FetchContent_Declare( | ||
| boost | ||
| URL https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.gz | ||
| URL_HASH SHA256=c0685b68dd44cc46574cce86c4e17c0f611b15e195be9848dfd0769a0a207628 | ||
| ) | ||
| FetchContent_MakeAvailable(boost) | ||
| add_library(boost_headers INTERFACE) | ||
| target_include_directories(boost_headers INTERFACE ${boost_SOURCE_DIR}) | ||
|
|
||
| # pybind11 | ||
| FetchContent_Declare( | ||
| pybind11 | ||
| GIT_REPOSITORY https://github.com/pybind/pybind11.git | ||
| GIT_TAG v2.11.1 | ||
| ) | ||
| set(PYBIND11_TEST OFF CACHE BOOL "" FORCE) | ||
| FetchContent_MakeAvailable(pybind11) | ||
|
|
||
| set(OPT_COPTS -Ofast -fno-fast-math -march=native) | ||
|
|
||
| set(TESSERACT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
|
|
||
| # === Libraries === | ||
| add_library(common ${TESSERACT_SRC_DIR}/common.cc ${TESSERACT_SRC_DIR}/common.h) | ||
| target_include_directories(common PUBLIC ${TESSERACT_SRC_DIR}) | ||
| target_compile_options(common PRIVATE ${OPT_COPTS}) | ||
| target_link_libraries(common PUBLIC libstim Threads::Threads) | ||
|
|
||
| add_library(utils ${TESSERACT_SRC_DIR}/utils.cc ${TESSERACT_SRC_DIR}/utils.h) | ||
| target_include_directories(utils PUBLIC ${TESSERACT_SRC_DIR}) | ||
| target_compile_options(utils PRIVATE ${OPT_COPTS}) | ||
| target_link_libraries(utils PUBLIC common libstim Threads::Threads) | ||
|
|
||
| add_library(tesseract_lib ${TESSERACT_SRC_DIR}/tesseract.cc ${TESSERACT_SRC_DIR}/tesseract.h) | ||
| target_include_directories(tesseract_lib PUBLIC ${TESSERACT_SRC_DIR}) | ||
| target_compile_options(tesseract_lib PRIVATE ${OPT_COPTS}) | ||
| target_link_libraries(tesseract_lib PUBLIC utils boost_headers) | ||
|
|
||
| add_library(simplex ${TESSERACT_SRC_DIR}/simplex.cc ${TESSERACT_SRC_DIR}/simplex.h) | ||
| target_include_directories(simplex PUBLIC ${TESSERACT_SRC_DIR}) | ||
| target_compile_options(simplex PRIVATE ${OPT_COPTS}) | ||
| target_link_libraries(simplex PUBLIC common utils tesseract_lib highs libstim Threads::Threads) | ||
|
|
||
| # === Executables === | ||
| add_executable(tesseract ${TESSERACT_SRC_DIR}/tesseract_main.cc) | ||
| target_compile_options(tesseract PRIVATE ${OPT_COPTS}) | ||
| target_link_libraries(tesseract PRIVATE tesseract_lib argparse::argparse nlohmann_json::nlohmann_json) | ||
|
|
||
| add_executable(simplex_bin ${TESSERACT_SRC_DIR}/simplex_main.cc) | ||
| set_target_properties(simplex_bin PROPERTIES OUTPUT_NAME simplex) | ||
| target_compile_options(simplex_bin PRIVATE ${OPT_COPTS}) | ||
| target_link_libraries(simplex_bin PRIVATE common simplex argparse::argparse nlohmann_json::nlohmann_json) | ||
|
|
||
| # === Python module === | ||
| pybind11_add_module(tesseract_decoder MODULE ${TESSERACT_SRC_DIR}/tesseract.pybind.cc) | ||
| target_compile_options(tesseract_decoder PRIVATE ${OPT_COPTS}) | ||
| target_include_directories(tesseract_decoder PRIVATE ${TESSERACT_SRC_DIR}) | ||
| target_link_libraries(tesseract_decoder PRIVATE common utils simplex tesseract_lib) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,24 +15,36 @@ | |
| #include "simplex.h" | ||
|
|
||
| #include <cassert> | ||
| #include <iostream> | ||
|
|
||
| #include "Highs.h" | ||
| #include "io/HMPSIO.h" | ||
|
|
||
| constexpr size_t T_COORD = 2; | ||
|
|
||
| namespace { | ||
| void highs_log_cb(HighsLogType, const char* msg, void* user_data) { | ||
| CallbackStream* stream = static_cast<CallbackStream*>(user_data); | ||
| (*stream) << msg; | ||
| stream->flush(); | ||
| } | ||
| } // namespace | ||
|
|
||
| std::string SimplexConfig::str() { | ||
| auto& self = *this; | ||
| std::stringstream ss; | ||
| ss << "SimplexConfig("; | ||
| ss << "dem=" << "DetectorErrorModel_Object" << ", "; | ||
| ss << "window_length=" << self.window_length << ", "; | ||
| ss << "window_slide_length=" << self.window_slide_length << ", "; | ||
| ss << "verbose=" << self.verbose << ")"; | ||
| ss << "window_slide_length=" << self.window_slide_length << ")"; | ||
| return ss.str(); | ||
| } | ||
|
|
||
| SimplexDecoder::SimplexDecoder(SimplexConfig _config) : config(_config) { | ||
| if (!config.verbose_callback) { | ||
| config.verbose_callback = [](const std::string& s) { std::cout << s; }; | ||
| } | ||
| config.log_stream.callback = config.verbose_callback; | ||
| config.dem = common::remove_zero_probability_errors(config.dem); | ||
| std::vector<double> detector_t_coords(config.dem.count_detectors()); | ||
| for (const stim::DemInstruction& instruction : config.dem.flattened().instructions) { | ||
|
|
@@ -152,7 +164,11 @@ void SimplexDecoder::init_ilp() { | |
| // Disabled presolve entirely after encountering bugs similar to this one: | ||
| // https://github.com/ERGO-Code/HiGHS/issues/1273 | ||
| highs->setOptionValue("presolve", "off"); | ||
| highs->setOptionValue("output_flag", config.verbose); | ||
| highs->setOptionValue("output_flag", config.log_stream.active); | ||
| highs->setOptionValue("log_to_console", config.log_stream.active); | ||
| if (config.log_stream.active) { | ||
| highs->setLogCallback(highs_log_cb, &config.log_stream); | ||
| } | ||
| } | ||
|
|
||
| void SimplexDecoder::decode_to_errors(const std::vector<uint64_t>& detections) { | ||
|
|
@@ -197,9 +213,7 @@ void SimplexDecoder::decode_to_errors(const std::vector<uint64_t>& detections) { | |
| add_costs_for_time(t1); | ||
| ++t1; | ||
| } | ||
| if (config.verbose) { | ||
| std::cout << "t0 = " << t0 << " t1 = " << t1 << std::endl; | ||
| } | ||
| config.log_stream << "t0 = " << t0 << " t1 = " << t1 << std::endl; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also have this: |
||
|
|
||
| // Pass the model to HiGHS | ||
| *return_status = highs->passModel(*model); | ||
|
|
@@ -235,16 +249,19 @@ void SimplexDecoder::decode_to_errors(const std::vector<uint64_t>& detections) { | |
| } | ||
| assert(*return_status == HighsStatus::kOk); | ||
|
|
||
| if (config.verbose) { | ||
| // Get the solution information | ||
| if (config.log_stream.active) { | ||
| const HighsInfo& info = highs->getInfo(); | ||
| std::cout << "Simplex iteration count: " << info.simplex_iteration_count << std::endl; | ||
| std::cout << "Objective function value: " << info.objective_function_value << std::endl; | ||
| std::cout << "Primal solution status: " | ||
| << highs->solutionStatusToString(info.primal_solution_status) << std::endl; | ||
| std::cout << "Dual solution status: " | ||
| << highs->solutionStatusToString(info.dual_solution_status) << std::endl; | ||
| std::cout << "Basis: " << highs->basisValidityToString(info.basis_validity) << std::endl; | ||
| config.log_stream << "Simplex iteration count: " << info.simplex_iteration_count | ||
| << std::endl; | ||
| config.log_stream << "Objective function value: " << info.objective_function_value | ||
| << std::endl; | ||
| config.log_stream << "Primal solution status: " | ||
| << highs->solutionStatusToString(info.primal_solution_status) | ||
| << std::endl; | ||
| config.log_stream << "Dual solution status: " | ||
| << highs->solutionStatusToString(info.dual_solution_status) << std::endl; | ||
| config.log_stream << "Basis: " << highs->basisValidityToString(info.basis_validity) | ||
| << std::endl; | ||
| } | ||
|
|
||
| // Get the model status | ||
|
|
@@ -286,16 +303,17 @@ void SimplexDecoder::decode_to_errors(const std::vector<uint64_t>& detections) { | |
| *return_status = highs->run(); | ||
| assert(*return_status == HighsStatus::kOk); | ||
|
|
||
| if (config.verbose) { | ||
| // Get the solution information | ||
| if (config.log_stream.active) { | ||
| const HighsInfo& info = highs->getInfo(); | ||
| std::cout << "Simplex iteration count: " << info.simplex_iteration_count << std::endl; | ||
| std::cout << "Objective function value: " << info.objective_function_value << std::endl; | ||
| std::cout << "Primal solution status: " | ||
| << highs->solutionStatusToString(info.primal_solution_status) << std::endl; | ||
| std::cout << "Dual solution status: " | ||
| << highs->solutionStatusToString(info.dual_solution_status) << std::endl; | ||
| std::cout << "Basis: " << highs->basisValidityToString(info.basis_validity) << std::endl; | ||
| config.log_stream << "Simplex iteration count: " << info.simplex_iteration_count << std::endl; | ||
| config.log_stream << "Objective function value: " << info.objective_function_value | ||
| << std::endl; | ||
| config.log_stream << "Primal solution status: " | ||
| << highs->solutionStatusToString(info.primal_solution_status) << std::endl; | ||
| config.log_stream << "Dual solution status: " | ||
| << highs->solutionStatusToString(info.dual_solution_status) << std::endl; | ||
| config.log_stream << "Basis: " << highs->basisValidityToString(info.basis_validity) | ||
| << std::endl; | ||
| } | ||
|
|
||
| // Get the model status | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is unrelated to the functionality in the PR title