Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Gheorghiu <[email protected]>
  • Loading branch information
vsoftco committed Aug 30, 2024
1 parent 6cea622 commit e02533e
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 135 deletions.
12 changes: 7 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
`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_destructively()`
- `qpp::QEngineT<>::get_measured()` -> `qpp::QEngineT<>::get_measured_d()`
- `qpp::QEngineT<>::get_non_measured()` ->
`qpp::QEngineT<>::get_non_measured_destructively()`
- `qpp::QEngineT<>::was_measured()` ->
`qpp::QEngineT<>::was_measured_destructively()`
`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
Expand Down
191 changes: 96 additions & 95 deletions include/qpp/classes/qcircuit.hpp

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions include/qpp/classes/qengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
*/
void set_measured_destructively_(idx i) {
// EXCEPTION CHECKS
if (was_measured_destructively(i)) {
if (was_measured_d(i)) {
throw exception::QuditAlreadyMeasured(
"qpp::QEngineT::set_measured_()", "i");
}
// END EXCEPTION CHECKS
qeng_st_.subsys_[i] = std::numeric_limits<idx>::max(); // set qudit i to
// measured state
for (idx m = i; m < this->qc_ptr_->get_nq(); ++m) {
if (!was_measured_destructively(m)) {
if (!was_measured_d(m)) {
--qeng_st_.subsys_[m];
}
}
Expand All @@ -446,7 +446,7 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
idx vsize = v.size();
for (idx i = 0; i < vsize; ++i) {
// EXCEPTION CHECKS
if (was_measured_destructively(v[i])) {
if (was_measured_d(v[i])) {
throw exception::QuditAlreadyMeasured(
"qpp::QEngineT::get_relative_pos_()", "v[i]");
}
Expand Down Expand Up @@ -898,7 +898,7 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
* \param i Qudit index
* \return True if qudit \a i was already measured, false otherwise
*/
bool was_measured_destructively(idx i) const {
bool was_measured_d(idx i) const {
return qeng_st_.subsys_[i] == std::numeric_limits<idx>::max();
}

Expand All @@ -909,10 +909,10 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
* \return Vector of already measured qudit (destructively) indexes at
* the current engine state
*/
std::vector<idx> get_measured_destructively() const {
std::vector<idx> get_measured_d() const {
std::vector<idx> result;
for (idx i = 0; i < this->qc_ptr_->get_nq(); ++i) {
if (was_measured_destructively(i)) {
if (was_measured_d(i)) {
result.emplace_back(i);
}
}
Expand All @@ -925,10 +925,10 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
*
* \return Vector of non-measured (destructively) qudit indexes
*/
std::vector<idx> get_non_measured_destructively() const {
std::vector<idx> get_non_measured_d() const {
std::vector<idx> result;
for (idx i = 0; i < this->qc_ptr_->get_nq(); ++i) {
if (!was_measured_destructively(i)) {
if (!was_measured_d(i)) {
result.emplace_back(i);
}
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
*/
QEngineT& set_state(const T& state) override {
// EXCEPTION CHECKS
idx n = get_non_measured_destructively().size();
idx n = get_non_measured_d().size();
idx D = internal::safe_pow(this->qc_ptr_->get_d(), n);
if constexpr (std::is_same_v<T, ket>) {
if (static_cast<idx>(state.rows()) != D) {
Expand Down Expand Up @@ -1240,14 +1240,12 @@ class QEngineT : public QBaseEngine<T, QCircuit> {
ss << "\"sampling\": " << (qeng_st_.can_sample_ ? "true" : "false")
<< ", ";
ss << "\"measured/discarded (destructively)\": ";
ss << disp(get_measured_destructively(),
IOManipContainerOpts{}.set_sep(", "));
ss << disp(get_measured_d(), IOManipContainerOpts{}.set_sep(", "));
result += ss.str() + ", ";

ss.str("");
ss.clear();
ss << disp(get_non_measured_destructively(),
IOManipContainerOpts{}.set_sep(", "));
ss << disp(get_non_measured_d(), IOManipContainerOpts{}.set_sep(", "));
result += "\"non-measured (destructively)/non-discarded\": " + ss.str();

ss.str("");
Expand Down
2 changes: 1 addition & 1 deletion include/qpp/classes/qnoisy_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class QNoisyEngineT : public QEngineT<T> {
const typename QCircuitTraits<QCircuit>::value_type& elem) override {
// get the relative position of the target
std::vector<idx> target_rel_pos =
this->get_relative_pos_(this->get_non_measured_destructively());
this->get_relative_pos_(this->get_non_measured_d());

// apply the noise
for (idx i : target_rel_pos) {
Expand Down
6 changes: 3 additions & 3 deletions pyqpp/include/pyqpp/classes/qcircuit_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ inline void init_classes_qcircuit(py::module_& m) {
"(Total) Gate count", py::arg("U") = std::nullopt)
.def("get_gate_depth", &QCircuit::get_gate_depth,
"(Total) Gate depth", py::arg("U") = std::nullopt)
.def("get_measured", &QCircuit::get_measured,
.def("get_measured_d", &QCircuit::get_measured_d,
"Vector of already measured qudit indexes")
.def("get_measured_nd", &QCircuit::get_measured_nd,
"Vector of already measured non-destructively qudit indexes")
Expand All @@ -285,7 +285,7 @@ inline void init_classes_qcircuit(py::module_& m) {
"measurements (either destructive or non-destructive)")
.def("get_name", &QCircuit::get_name, "Description name")
.def("get_nc", &QCircuit::get_nc, "Number of classical dits")
.def("get_non_measured", &QCircuit::get_non_measured,
.def("get_non_measured_d", &QCircuit::get_non_measured_d,
"Non-measured qudit indexes")
.def("get_nop_count", &QCircuit::get_nop_count, "No-op count")
.def("get_nq", &QCircuit::get_nq, "Number of qudits")
Expand Down Expand Up @@ -445,7 +445,7 @@ inline void init_classes_qcircuit(py::module_& m) {
.def("to_JSON", &QCircuit::to_JSON,
"Displays the quantum circuit description in JSON format",
py::arg("enclosed_in_curly_brackets") = true)
.def("was_measured", &QCircuit::was_measured,
.def("was_measured_d", &QCircuit::was_measured_d,
"Whether qudit i was already measured", py::arg("i"))
.def("was_measured_nd", &QCircuit::was_measured_nd,
"Whether qudit i was already measured non-destructively",
Expand Down
9 changes: 3 additions & 6 deletions pyqpp/include/pyqpp/classes/qengine_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ void declare_QEngineT(py::module& m) {
&QEngineT<T>::get_max_post_selection_reps,
"Maximum number of repetitions of a cirucit post-selection step "
"until success")
.def("get_measured_destructively",
&QEngineT<T>::get_measured_destructively,
.def("get_measured_d", &QEngineT<T>::get_measured_d,
"Vector of already destructively measured qudit indexes")
.def("get_non_measured_destructively",
&QEngineT<T>::get_non_measured_destructively,
.def("get_non_measured_d", &QEngineT<T>::get_non_measured_d,
"Vector of qudit indexes that were not measured destructively")
.def("get_probs", &QEngineT<T>::get_probs,
"Underlying measurement outcome probabilities")
Expand Down Expand Up @@ -114,8 +112,7 @@ void declare_QEngineT(py::module& m) {
.def("to_JSON", &QEngineT<T>::to_JSON,
"State of the engine in JSON format",
py::arg("enclosed_in_curly_brackets") = true)
.def("was_measured_destructively",
&QEngineT<T>::was_measured_destructively,
.def("was_measured_d", &QEngineT<T>::was_measured_d,
"Whether qudit i was already measured destructively", py::arg("i"))

.def("traits_get_name", &QEngineT<T>::traits_get_name, "Engine name")
Expand Down
12 changes: 6 additions & 6 deletions unit_tests/tests/classes/qcircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ TEST(qpp_QCircuit_get_gate_count, SpecificGateCount) {}
TEST(qpp_QCircuit_get_gate_depth, TotalGateDepth) {}
TEST(qpp_QCircuit_get_gate_depth, SpecificGateDepth) {}

/// BEGIN std::vector<idx> QCircuit::get_measured() const
TEST(qpp_QCircuit_get_measured, AllTests) {}
/// BEGIN std::vector<idx> QCircuit::get_measured_d() const
TEST(qpp_QCircuit_get_measured_d, AllTests) {}

/// BEGIN std::vector<idx> QCircuit::get_measured_nd() const
TEST(qpp_QCircuit_get_measured_nd, AllTests) {}
Expand All @@ -225,8 +225,8 @@ TEST(qpp_QCircuit_get_name, AllTests) {}
/// BEGIN idx QCircuit::get_nc() const noexcept
TEST(qpp_QCircuit_get_nc, AllTests) {}

/// BEGIN std::vector<idx> QCircuit::get_non_measured() const
TEST(qpp_QCircuit_get_non_measured, AllTests) {}
/// BEGIN std::vector<idx> QCircuit::get_non_measured_d() const
TEST(qpp_QCircuit_get_non_measured_d, AllTests) {}

/// BEGIN idx QCircuit::get_nop_count() const
TEST(qpp_QCircuit_get_nop_count, AllTests) {}
Expand Down Expand Up @@ -429,8 +429,8 @@ TEST(qpp_QCircuit_TFQ, SpecificQudits) {}
/// const override
TEST(qpp_QCircuit_to_JSON, AllTests) {}

/// BEGIN bool QCircuit::was_measured(idx i) const
TEST(qpp_QCircuit_was_measured, AllTests) {}
/// BEGIN bool QCircuit::was_measured_d(idx i) const
TEST(qpp_QCircuit_was_measured_d, AllTests) {}

/// BEGIN bool QCircuit::was_measured_nd(idx i) const
TEST(qpp_QCircuit_was_measured_nd, AllTests) {}
Expand Down
12 changes: 6 additions & 6 deletions unit_tests/tests/classes/qengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ TEST(qpp_QEngineT_get_ensure_post_selection, AllTests) {}
/// BEGIN idx QEngineT::get_max_post_selection_reps() const
TEST(qpp_QEngineT_get_max_post_selection_reps, AllTests) {}

/// BEGIN std::vector<idx> QEngineT::get_measured_destructively() const
TEST(qpp_QEngineT_get_measured_destructively, AllTests) {}
/// BEGIN std::vector<idx> QEngineT::get_measured_d() const
TEST(qpp_QEngineT_get_measured_d, AllTests) {}

/// BEGIN std::vector<idx> QEngineT::get_non_measured_destructively() const
TEST(qpp_QEngineT_get_non_measured_destructively, AllTests) {}
/// BEGIN std::vector<idx> QEngineT::get_non_measured_d() const
TEST(qpp_QEngineT_get_non_measured_d, AllTests) {}

/// BEGIN std::vector<realT> QEngineT::get_probs() const
TEST(qpp_QEngineT_get_probs, AllTests) {}
Expand Down Expand Up @@ -88,5 +88,5 @@ TEST(qpp_QEngineT_traits_is_noisy, AllTests) {}
/// BEGIN bool QEngineT::traits_is_pure() const override
TEST(qpp_QEngineT_traits_is_pure, AllTests) {}

/// BEGIN bool QEngineT::was_measured_destructively(idx i) const
TEST(qpp_QEngineT_was_measured_destructively, AllTests) {}
/// BEGIN bool QEngineT::was_measured_d(idx i) const
TEST(qpp_QEngineT_was_measured_d, AllTests) {}

0 comments on commit e02533e

Please sign in to comment.