Skip to content

Commit

Permalink
Post select (#177)
Browse files Browse the repository at this point in the history
Added support for post-selection
  • Loading branch information
vsoftco authored Sep 5, 2024
1 parent 46c8c98 commit 914c19a
Show file tree
Hide file tree
Showing 137 changed files with 4,867 additions and 3,147 deletions.
207 changes: 207 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
FormatStyle: file
# WarningsAsErrors: "*"
Checks: "-*,
abseil-*,\
-abseil-string-find-startswith,\
-abseil-string-find-str-contains,\
bugprone-*,\
-bugprone-argument-comment,\
-bugprone-assert-side-effect,\
-bugprone-bad-signal-to-kill-thread,\
-bugprone-bool-pointer-implicit-conversion,\
-bugprone-branch-clone,\
-bugprone-copy-constructor-init,\
-bugprone-dangling-handle,\
-bugprone-dynamic-static-initializers,\
-bugprone-easily-swappable-parameters,\
-bugprone-exception-escape,\
-bugprone-fold-init-type,\
-bugprone-forward-declaration-namespace,\
-bugprone-forwarding-reference-overload,\
-bugprone-implicit-widening-of-multiplication-result,\
-bugprone-inaccurate-erase,\
-bugprone-incorrect-roundings,\
-bugprone-infinite-loop,\
-bugprone-integer-division,\
-bugprone-lambda-function-name,\
-bugprone-macro-parentheses,\
-bugprone-macro-repeated-side-effects,\
-bugprone-misplaced-operator-in-strlen-in-alloc,\
-bugprone-misplaced-widening-cast,\
-bugprone-move-forwarding-reference,\
-bugprone-multiple-statement-macro,\
-bugprone-narrowing-conversions,\
-bugprone-no-escape,\
-bugprone-not-null-terminated-result,\
-bugprone-parent-virtual-call,\
-bugprone-posix-return,\
-bugprone-redundant-branch-condition,\
-bugprone-reserved-identifier,\
-bugprone-signal-handler,\
-bugprone-signed-char-misuse,\
-bugprone-sizeof-container,\
-bugprone-sizeof-expression,\
-bugprone-spuriously-wake-up-functions,\
-bugprone-string-constructor,\
-bugprone-string-integer-assignment,\
-bugprone-string-literal-with-embedded-nul,\
-bugprone-stringview-nullptr,\
-bugprone-suspicious-enum-usage,\
-bugprone-suspicious-include,\
-bugprone-suspicious-memory-comparison,\
-bugprone-suspicious-memset-usage,\
-bugprone-suspicious-missing-comma,\
-bugprone-suspicious-semicolon,\
-bugprone-suspicious-string-compare,\
-bugprone-swapped-arguments,\
-bugprone-terminating-continue,\
-bugprone-throw-keyword-missing,\
-bugprone-too-small-loop-variable,\
-bugprone-undefined-memory-manipulation,\
-bugprone-undelegated-constructor,\
-bugprone-unhandled-exception-at-new,\
-bugprone-unhandled-self-assignment,\
-bugprone-unused-raii,\
-bugprone-unused-return-value,\
-bugprone-use-after-move,\
-bugprone-virtual-near-miss,\
cert-*,\
-cert-dcl16-c,\
-cert-dcl21-cpp,\
-cert-dcl37-c,\
-cert-dcl50-cpp,\
-cert-dcl51-cpp,\
-cert-dcl54-cpp,\
-cert-dcl58-cpp,\
-cert-err33-c,\
-cert-msc30-c,\
-cert-msc32-c,\
-cert-msc50-cpp,\
-cert-msc51-cpp,\
-cert-oop54-cpp,\
-cert-str34-c,\
-cert-str34-c,\
-cert-str34-c,\
-cert-str34-c,\
-clang-analyzer-*,\
concurrency-*,\
-concurrency-mt-unsafe,\
cppcoreguidelines-*,\
-concurrency-mt-unsafe,\
-cppcoreguidelines-avoid-c-arrays,\
-cppcoreguidelines-avoid-const-or-ref-data-members,\
-cppcoreguidelines-avoid-do-while,\
-cppcoreguidelines-avoid-goto,\
-cppcoreguidelines-avoid-magic-numbers,\
-cppcoreguidelines-avoid-non-const-global-variables,\
-cppcoreguidelines-c-copy-assignment-signature,\
-cppcoreguidelines-explicit-virtual-functions,\
-cppcoreguidelines-init-variables,\
-cppcoreguidelines-interfaces-global-init,\
-cppcoreguidelines-macro-usage,\
-cppcoreguidelines-narrowing-conversions,\
-cppcoreguidelines-no-malloc,\
-cppcoreguidelines-non-private-member-variables-in-classes,\
-cppcoreguidelines-owning-memory,\
-cppcoreguidelines-prefer-member-initializer,\
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
-cppcoreguidelines-pro-type-const-cast,\
-cppcoreguidelines-pro-type-member-init,\
-cppcoreguidelines-pro-type-reinterpret-cast,\
-cppcoreguidelines-pro-type-static-cast-downcast,\
-cppcoreguidelines-pro-type-union-access,\
-cppcoreguidelines-pro-type-vararg,\
-cppcoreguidelines-slicing,\
-cppcoreguidelines-special-member-functions,\
-cppcoreguidelines-virtual-class-destructor,\
google-*,\
-google-default-arguments,\
-google-explicit-constructor,\
-google-readability-avoid-underscore-in-googletest-name,\
-google-readability-braces-around-statements,\
-google-readability-casting,\
-google-readability-namespace-comments,\
-google-readability-todo,\
-google-runtime-int,\
-google-upgrade-googletest-case,\
misc-*,\
-misc-misplaced-const,\
-misc-new-delete-overloads,\
-misc-non-private-member-variables-in-classes,\
-misc-no-recursion,\
-misc-redundant-expression,\
-misc-uniqueptr-reset-release,\
-misc-unconventional-assign-operator,\
-misc-unused-parameters,\
-misc-unused-using-decls,\
modernize-*,\
-modernize-avoid-c-arrays,\
-modernize-concat-nested-namespaces,\
-modernize-deprecated-headers,\
-modernize-loop-convert,\
-modernize-macro-to-enum,\
-modernize-make-unique,\
-modernize-pass-by-value,\
-modernize-raw-string-literal,\
-modernize-redundant-void-arg,\
-modernize-return-braced-init-list,\
-modernize-unary-static-assert,\
-modernize-use-auto,\
-modernize-use-bool-literals,\
-modernize-use-default-member-init,\
-modernize-use-emplace,\
-modernize-use-equals-default,\
-modernize-use-equals-delete,\
-modernize-use-nodiscard,\
-modernize-use-override,\
-modernize-use-trailing-return-type,\
-modernize-use-transparent-functors,\
-modernize-use-using,\
performance-*,\
-performance-faster-string-find,\
-performance-for-range-copy,\
-performance-inefficient-algorithm,\
-performance-inefficient-string-concatenation,\
-performance-inefficient-vector-operation,\
-performance-move-const-arg,\
-performance-no-automatic-move,\
-performance-noexcept-move-constructor,\
-performance-no-int-to-ptr,\
-performance-trivially-destructible,\
-performance-unnecessary-copy-initialization,\
-performance-unnecessary-value-param,\
portability-*,\
readability-*,\
-readability-avoid-const-params-in-decls,\
-readability-braces-around-statements,\
-readability-const-return-type,\
-readability-container-data-pointer,\
-readability-container-size-empty,\
-readability-convert-member-functions-to-static,\
-readability-else-after-return,\
-readability-function-cognitive-complexity,\
-readability-identifier-length,\
-readability-implicit-bool-conversion,\
-readability-inconsistent-declaration-parameter-name,\
-readability-isolate-declaration,\
-readability-magic-numbers,\
-readability-make-member-function-const,\
-readability-named-parameter,\
-readability-non-const-parameter,\
-readability-qualified-auto,\
-readability-redundant-access-specifiers,\
-readability-redundant-control-flow,\
-readability-redundant-declaration,\
-readability-redundant-member-init,\
-readability-redundant-smartptr-get,\
-readability-redundant-string-cstr,\
-readability-redundant-string-init,\
-readability-simplify-boolean-expr,\
-readability-static-accessed-through-instance,\
-readability-static-definition-in-anonymous-namespace,\
-readability-suspicious-call-argument,\
-readability-uppercase-literal-suffix,\
-readability-use-anyofallof
"
9 changes: 5 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
Expand Down Expand Up @@ -67,10 +68,10 @@ jobs:
- name: Install pyqpp
shell: bash
run: |
python3 -m venv venv
python3 -mvenv venv
if [ "$RUNNER_OS" == "Windows" ]; then
venv/Scripts/activate
venv\Scripts\Activate
else
. venv/bin/activate
source venv/bin/activate
fi
pip3 install .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mat.txt
examples/_*.cpp
out.tmp
TODO.txt
test

# pyqpp
Makefile
Expand Down
66 changes: 56 additions & 10 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# Pre-release

- Breaking change: renamed ["qpp/qpp.h"] to ["qpp/qpp.hpp"]
- New feature: implemented support for post-selection in
["qpp/classes/qengine.hpp"] and ["qpp/classes/qcircuit.hpp"]
- Implemented `qpp::QCircuit::`
- `QCircuit& post_select()` - destructive/non-destructive post-selection of
single/multiple qudits in the Z basis
- `QCircuit& post_selectV()` - destructive/non-destructive post-selection of
single/multiple qudits in an arbitrary orthonormal basis
- Implemented `qpp::QEngineT<>::`
- `bool get_ensure_post_selection() const` - True if post-selection is
enforced, false otherwise
- `QEngineT<>& set_ensure_post_selection()` - Enforces post-selection (i.e.,
post-selection steps are repeated until success)
- `idx get_max_post_selection_reps() const` - Maximum number of executions of
a circuit post-selection step until success
- `QEngineT<>& set_max_post_selection_reps()` - Sets the maximum number of
executions of a circuit post-selection step until success
- `bool post_select_ok() const` - True if post-selection was successful (or
absent), false otherwise
- Added
[["examples/circuits/post_selection.cpp"](https://github.com/softwareQinc/qpp/blob/main/examples/circuits/post_selection.cpp)]
example
- Refactored `qpp::QCircuit::GateStep/MeasurementStep/NOPStep` into separate
files ["qpp/internal/classes/qcircuit_gate_step.hpp"],
["qpp/internal/classes/qcircuit_measurement_step.hpp"], and
["qpp/internal/classes/qcircuit_nop_step.hpp"], respectively
- Refactored `qpp::QCircuit::Resources` into an independent class in a separate
file ["qpp/internal/classes/qcircuit_resources.hpp"]
- Refactored qpp::QCircuit::iterator class into an independent class, defined
outside qpp::QCircuit in ["qpp/classes/qcircuit.hpp"]
- Refactored `qpp::internal::QEngineState` and
`qpp::internal::QEngineStatistics`
in separate files, ["qpp/internal/classes/qengine_state.hpp"] and
["qpp/internal/classes/qengine_statistics.hpp"], respectively
- API changes in ["qpp/classes/qcircuit.hpp"]
- `qpp::QCircuit::get_measured()` -> `qpp::QCircuit::get_measured_d()`
- `qpp::QCircuit::get_non_measured()` -> `qpp::QCircuit::get_non_measured_d()`
- `qpp::QCircuit::was_measured()` -> `qpp::QCircuit::was_measured_d()`
- API changes in ["qpp/classes/qengine.hpp"]
- `qpp::QEngineT<>::get_measured()` -> `qpp::QEngineT<>::get_measured_d()`
- `qpp::QEngineT<>::get_non_measured()` ->
`qpp::QEngineT<>::get_non_measured_d()`
- `qpp::QEngineT<>::was_measured()` -> `qpp::QEngineT<>::was_measured_d()`
- Bugfix in qpp::internal::canonical_form(), the re-ordering is now stable, so
qpp::QCircuit measurement probabilities are not displayed in reversed order
w.r.t. target
- Simplified MATLAB detection via CMake `find_package()` function. Users should
only use `-DQPP_MATLAB=ON` when building with MATLAB support, all other
MATLAB-related CMake flags have been removed.
Expand All @@ -25,17 +71,17 @@
- ["qpp/classes/qnoisy_engine.hpp"] - noisy quantum engines
- Introduced ["qpp/classes/qengine_traits.hpp"] that implement
engine traits at run-time. All engines are now deriving from it.
The traits implements qpp::IQEngineTraits::
The traits implements `qpp::IQEngineTraits::`
- `std::string traits_get_name() const` - Engine's name
- `bool traits_is_noisy() const` - Simulates noisy execution
- `bool traits_is_pure() const` - Operates on pure states
- API changes in ["qpp/classes/qengine.hpp"] and
["qpp/classes/qnoisy_engine.hpp"]
- Enabled mixed-state engines by refactoring
`qpp::QEngine` -> `template<typename T> qpp::QEngineT<T>`
`qpp::QNoisyEngine` -> `template<typename T> qpp::QNoisyEngineT<T>`
The template argument T is restricted to `qpp::ket` (pure state
engines) and `qpp::cmat` (mixed states engines)
- `qpp::QEngine` -> `template<typename T> qpp::QEngineT<T>`
- `qpp::QNoisyEngine` -> `template<typename T> qpp::QNoisyEngineT<T>`
The template argument T is restricted to `qpp::ket` (pure state
engines) and `qpp::cmat` (mixed states engines)
- The following additional engines are now available
- `qpp::QEngine` - pure state ideal engine, backwards
compatibility
Expand All @@ -45,8 +91,8 @@
compatibility
- `qpp::QKetNoisyEngine` - same as `qpp::QNoisyEngine`
- `qpp::QDensityNoisyEngine` - mixed state noisy engine
- Renamed `qpp::QEngineT::get_psi()` -> `qpp::QEngineT::get_state()`
- Removed `qpp::QEngineT::is_noisy()`
- Renamed `qpp::QEngineT<>::get_psi()` -> `qpp::QEngineT<>::get_state()`
- Removed `qpp::QEngineT<>::is_noisy()`
- Added the new engines to **pyqpp**, which now defines the following
factory functions for instantiating engines
- `pyqpp.QEngine()` - pure state ideal engine, backwards
Expand All @@ -58,9 +104,9 @@
- `pyqpp.QKetNoisyEngine()` - same as `pyqpp.QNoisyEngine()`
- `pyqpp.QDensityNoisyEngine()` - mixed state noisy engine
- Removed the default argument `bool try_sampling = true` in
`qpp::QEngineT::execute(idx reps = 1, bool try_sampling = true)` ->
`qpp::QEngineT::execute(idx reps = 1)`
so now `qpp::QEngineT` will always try to sample from the output when
`qpp::QEngineT<>::execute(idx reps = 1, bool try_sampling = true)` ->
`qpp::QEngineT<>::execute(idx reps = 1)`
so now `qpp::QEngineT<>` will always try to sample from the output when
the circuit is executed multiple times (i.e., when `reps > 1`)
- Introduced no-op (dummy) quantum engines in ["qpp/classes/qdummy_engine.hpp"]
that provides
Expand Down
Loading

0 comments on commit 914c19a

Please sign in to comment.