Skip to content

Commit

Permalink
🎨 Misc. code quality improvements (#547)
Browse files Browse the repository at this point in the history
## Description

This PR brings in a couple code quality improvements discovered when
working on #538.

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.
  • Loading branch information
burgholzer authored Feb 7, 2024
2 parents f3e105e + ade870e commit 2141558
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
7 changes: 7 additions & 0 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ function(enable_project_options target_name)
check_pie_supported()
set_target_properties(${target_name} PROPERTIES INTERFACE_POSITION_INDEPENDENT_CODE ON)
endif()

# add a compile definition for _LIBCPP_REMOVE_TRANSITIVE_INCLUDES to remove transitive includes
# from libc++ headers. This is useful to avoid including system headers that are not needed and
# that may conflict with other headers. This is only supported by libc++.
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_compile_definitions(${target_name} INTERFACE _LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
endif()
endfunction()
14 changes: 7 additions & 7 deletions src/parsers/qasm3_parser/passes/ConstEvalPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ ConstEvalValue ConstEvalPass::evalFloatExpression(BinaryExpression::Op op,

switch (op) {
case BinaryExpression::Power:
result.value = pow(lhs, rhs);
result.value = std::pow(lhs, rhs);
break;
case BinaryExpression::Add:
result.value = lhs + rhs;
Expand Down Expand Up @@ -411,42 +411,42 @@ std::optional<ConstEvalValue> ConstEvalPass::visitUnaryExpression(
return std::nullopt;
case UnaryExpression::Sin:
if (val->type == ConstEvalValue::Type::ConstFloat) {
val->value = sin(std::get<1>(val->value));
val->value = std::sin(std::get<1>(val->value));
} else {
return std::nullopt;
}
break;
case UnaryExpression::Cos:
if (val->type == ConstEvalValue::Type::ConstFloat) {
val->value = cos(std::get<1>(val->value));
val->value = std::cos(std::get<1>(val->value));
} else {
return std::nullopt;
}
break;
case UnaryExpression::Tan:
if (val->type == ConstEvalValue::Type::ConstFloat) {
val->value = tan(std::get<1>(val->value));
val->value = std::tan(std::get<1>(val->value));
} else {
return std::nullopt;
}
break;
case UnaryExpression::Exp:
if (val->type == ConstEvalValue::Type::ConstFloat) {
val->value = exp(std::get<1>(val->value));
val->value = std::exp(std::get<1>(val->value));
} else {
return std::nullopt;
}
break;
case UnaryExpression::Ln:
if (val->type == ConstEvalValue::Type::ConstFloat) {
val->value = log(std::get<1>(val->value));
val->value = std::log(std::get<1>(val->value));
} else {
return std::nullopt;
}
break;
case UnaryExpression::Sqrt:
if (val->type == ConstEvalValue::Type::ConstFloat) {
val->value = sqrt(std::get<1>(val->value));
val->value = std::sqrt(std::get<1>(val->value));
} else {
return std::nullopt;
}
Expand Down
64 changes: 33 additions & 31 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
pybind11_add_module(
# Name of the extension
_core
# Prefer thin LTO if available
THIN_LTO
# Optimize the bindings for size
OPT_SIZE
# Source code goes here
${MQT_CORE_INCLUDE_BUILD_DIR}/python/pybind11.hpp
module.cpp
register_operations.cpp
register_permutation.cpp
register_symbolic.cpp
register_quantum_computation.cpp
operations/register_optype.cpp
operations/register_control.cpp
operations/register_operation.cpp
operations/register_standard_operation.cpp
operations/register_classic_controlled_operation.cpp
operations/register_compound_operation.cpp
operations/register_non_unitary_operation.cpp
operations/register_symbolic_operation.cpp
symbolic/register_variable.cpp
symbolic/register_term.cpp
symbolic/register_expression.cpp)
target_link_libraries(_core PRIVATE MQT::Core MQT::ProjectOptions MQT::ProjectWarnings)
if(NOT TARGET _core)
pybind11_add_module(
# Name of the extension
_core
# Prefer thin LTO if available
THIN_LTO
# Optimize the bindings for size
OPT_SIZE
# Source code goes here
${MQT_CORE_INCLUDE_BUILD_DIR}/python/pybind11.hpp
module.cpp
register_operations.cpp
register_permutation.cpp
register_symbolic.cpp
register_quantum_computation.cpp
operations/register_optype.cpp
operations/register_control.cpp
operations/register_operation.cpp
operations/register_standard_operation.cpp
operations/register_classic_controlled_operation.cpp
operations/register_compound_operation.cpp
operations/register_non_unitary_operation.cpp
operations/register_symbolic_operation.cpp
symbolic/register_variable.cpp
symbolic/register_term.cpp
symbolic/register_expression.cpp)
target_link_libraries(_core PRIVATE MQT::Core MQT::ProjectOptions MQT::ProjectWarnings)

# Install directive for scikit-build-core
install(
TARGETS _core
DESTINATION .
COMPONENT MQTCorePythonModule)
# Install directive for scikit-build-core
install(
TARGETS _core
DESTINATION .
COMPONENT MQTCorePythonModule)
endif()

0 comments on commit 2141558

Please sign in to comment.