Skip to content

Comments

use Exception instead of std exceptions#500

Merged
evaleev merged 1 commit intomasterfrom
evaleev/feature/use-sq-exception-throughout
Feb 18, 2026
Merged

use Exception instead of std exceptions#500
evaleev merged 1 commit intomasterfrom
evaleev/feature/use-sq-exception-throughout

Conversation

@evaleev
Copy link
Member

@evaleev evaleev commented Feb 18, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes error handling across SeQuant by replacing uses of std::runtime_error / std::logic_error / std::invalid_argument / etc. with the project’s custom sequant::Exception, and updates unit tests and Doxygen @throw annotations accordingly.

Changes:

  • Replaced standard-library exception types with sequant::Exception across core, MBPT domain, export, eval backends, and serialization code.
  • Updated unit tests to assert Exception is thrown instead of STL exception types.
  • Removed many now-unneeded <stdexcept> includes and added exception.hpp where required.

Reviewed changes

Copilot reviewed 60 out of 60 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/test_wick.cpp Update expected thrown type to Exception for deprecated spinfree() mismatch cases.
tests/unit/test_utilities.cpp Update singleton tests to expect/catch sequant::Exception.
tests/unit/test_tensor_network.cpp Update tensor network tests to expect Exception for invalid constructions/connections.
tests/unit/test_math.cpp Update to_rational(NaN) test to expect Exception.
tests/unit/test_latex.cpp Update narrow-string Unicode error tests to expect Exception.
tests/unit/test_expr.cpp Update constant conversion/adjoint tests to expect Exception for unsupported operations.
SeQuant/domain/mbpt/vac_av.cpp Throw Exception for unknown expression types.
SeQuant/domain/mbpt/utils.cpp Throw Exception for unsupported expression/term types.
SeQuant/domain/mbpt/spin.cpp Replace various std::runtime_error throws with Exception for unsupported expression structures.
SeQuant/domain/mbpt/op_registry.cpp Add exception.hpp include and switch registry validation errors to Exception.
SeQuant/domain/mbpt/op.hpp Replace std::logic_error with Exception for unknown vacuum type.
SeQuant/domain/mbpt/op.cpp Replace std::runtime_error / std::invalid_argument with Exception in vacuum/context validation.
SeQuant/domain/mbpt/biorthogonalization.cpp Update throws and @throw docs to use Exception.
SeQuant/core/wick.impl.hpp Throw Exception for invalid nested Sum structure in input.
SeQuant/core/wick.hpp Replace throws and @throw docs with Exception.
SeQuant/core/utility/singleton.hpp Include exception.hpp and throw Exception for singleton lifecycle errors.
SeQuant/core/utility/indices.hpp Throw Exception for unsupported expression types in get_unique_indices.
SeQuant/core/utility/expr.hpp Throw Exception for unimplemented composite replacements.
SeQuant/core/utility/expr.cpp Throw Exception for invalid expression types during transforms/popping.
SeQuant/core/tensor_network/v3.hpp Replace std::invalid_argument with Exception for edge/tensor validation.
SeQuant/core/tensor_network/v3.cpp Throw Exception for unsupported recursive protoindices.
SeQuant/core/tensor_network/v2.hpp Replace std::logic_error / std::invalid_argument with Exception for connection/tensor validation.
SeQuant/core/tensor_network/v2.cpp Throw Exception for unsupported recursive protoindices.
SeQuant/core/tensor_network/v1.hpp Replace std::logic_error with Exception for invalid connections / non-tensor inputs.
SeQuant/core/tensor_network/v1.cpp Throw Exception for unsupported recursive protoindices.
SeQuant/core/tensor_canonicalizer.hpp Update @throw docs to reference Exception.
SeQuant/core/tensor_canonicalizer.cpp Throw Exception when canonicalizer is not registered.
SeQuant/core/space.hpp Make IndexSpace::bad_key derive from Exception.
SeQuant/core/space.cpp Throw Exception when index space registry is unavailable.
SeQuant/core/runtime.hpp Include exception.hpp and throw Exception on invalid thread count.
SeQuant/core/rational.hpp Throw Exception for NaN/Inf and rationalization failures.
SeQuant/core/op.hpp Replace std::logic_error / std::invalid_argument with Exception for unsupported vacua/args.
SeQuant/core/io/serialization/v1/serialize.cpp Throw Exception for unsupported expr types in serializer.
SeQuant/core/io/serialization/v1/ast_conversions.hpp Catch Exception instead of std::invalid_argument to wrap index parsing errors.
SeQuant/core/io/latex/latex.hpp Include exception.hpp and update @throw docs to Exception.
SeQuant/core/io/latex/latex.cpp Throw Exception for narrow-char Unicode limitations.
SeQuant/core/index_space_registry.hpp Replace std::invalid_argument throws with Exception across registry validation.
SeQuant/core/index.hpp Replace std::invalid_argument with Exception in index validation.
SeQuant/core/hugenholtz.hpp Replace std::out_of_range with Exception for invalid insertion indices.
SeQuant/core/expressions/tensor.hpp Replace std::logic_error with Exception for invalid tensor rank.
SeQuant/core/expressions/expr.hpp Replace std::invalid_argument with Exception for visiting non-managed expressions; change not_implemented() return type to Exception.
SeQuant/core/expressions/expr.cpp Return Exception from not_implemented() helper.
SeQuant/core/expressions/constant.hpp Replace std::invalid_argument / std::logic_error with Exception in value conversion and arithmetic ops.
SeQuant/core/expressions/abstract_tensor.cpp Replace std::runtime_error with Exception for unsupported expr types.
SeQuant/core/export/text_generator.hpp Replace std::runtime_error with Exception for unsupported expr types.
SeQuant/core/export/python_einsum.hpp Replace multiple std::runtime_error with Exception for unsupported export conditions.
SeQuant/core/export/julia_tensor_operations.hpp Replace std::runtime_error with Exception for unsupported export conditions.
SeQuant/core/export/julia_tensor_operations.cpp Replace std::runtime_error with Exception for missing tags.
SeQuant/core/export/julia_tensor_kit.hpp Include exception.hpp and throw Exception for unsupported creation/representation cases.
SeQuant/core/export/julia_itensor.hpp Include exception.hpp and throw Exception for unsupported creation cases.
SeQuant/core/export/itf.hpp Replace std::runtime_error with Exception across ITF generation constraints.
SeQuant/core/export/itf.cpp Replace std::runtime_error with Exception for missing names/tags.
SeQuant/core/export/export.hpp Replace std::runtime_error with Exception for invalid node/group export scenarios.
SeQuant/core/eval/eval_expr.cpp Replace std::logic_error with Exception for unsupported binarize input.
SeQuant/core/eval/backends/tiledarray/result.hpp Include exception.hpp and throw Exception for invalid rank.
SeQuant/core/eval/backends/tapp/tensor.hpp Include exception.hpp and throw Exception on TAPP errors.
SeQuant/core/eval/backends/tapp/result.hpp Include exception.hpp and throw Exception for invalid rank.
SeQuant/core/eval/backends/btas/result.hpp Include exception.hpp and throw Exception for invalid rank.
SeQuant/core/context.hpp Update @throw docs to reference Exception.
SeQuant/core/binary_node.hpp Replace std::runtime_error with Exception for dereferencing null nodes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +12
#include <SeQuant/core/utility/exception.hpp>
#include <cassert>
#include <memory>
#include <mutex>
#include <stdexcept>

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Exception derives from std::exception, but SeQuant/core/utility/exception.hpp only includes <string>. Since this header no longer includes <stdexcept>, compilation can fail when std::exception is not available via transitive includes. Prefer adding #include <exception> to exception.hpp (or include <exception> here before including exception.hpp).

Copilot uses AI. Check for mistakes.
Comment on lines 14 to 17
#include <SeQuant/core/ranges.hpp>
#include <SeQuant/core/utility/conversion.hpp>
#include <SeQuant/core/utility/exception.hpp>

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

SeQuant/core/utility/exception.hpp defines sequant::Exception : std::exception but does not include <exception>. This file includes exception.hpp directly (and no longer includes <stdexcept>), so it may fail to compile depending on include order. Prefer adding <exception> to exception.hpp (or include it here).

Copilot uses AI. Check for mistakes.
throw std::logic_error(
throw Exception(
"WickTheorem::compute: spinfree=true supported only for physical "
"vacuum and for Fermi facuum");
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Typo in error message: "facuum" should be "vacuum".

Copilot uses AI. Check for mistakes.
@@ -376,11 +376,10 @@ class IndexSpace {

/// exception type thrown when ancountered unknown/invalid
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Typo in comment: "ancountered" should be "encountered".

Copilot uses AI. Check for mistakes.
@evaleev evaleev merged commit 2294679 into master Feb 18, 2026
22 checks passed
@evaleev evaleev deleted the evaleev/feature/use-sq-exception-throughout branch February 18, 2026 20:32
@evaleev evaleev added the enhancement New feature or request label Feb 18, 2026
@evaleev evaleev added this to the 2.2 milestone Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants