Skip to content

Commit

Permalink
allows QASM2 destructive measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
vsoftco committed Dec 21, 2021
1 parent 7a67ee1 commit 2f7c7c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Expand Up @@ -26,6 +26,7 @@ option(WITH_EXAMPLES "Enable example compilation" OFF)
option(WITH_UNIT_TESTS "Enable unit testing" OFF)
option(SANITIZE "Enable code sanitizing (only for gcc/clang)" OFF)
option(USE_OPENQASM2_SPECS "Use OpenQASM 2.0 standard instead of Qiskit gate specifications" OFF)
option(USE_OPENQASM2_DESTRUCTIVE_MEASUREMENTS "Use destructive measurements when executing OpenQASM 2.0 circuits" OFF)

#### Enable OpenQASM 2.0 specs, see DISCREPANCIES.md for a comparison with Qiskit
if (${USE_OPENQASM2_SPECS})
Expand All @@ -34,6 +35,14 @@ else ()
target_compile_definitions(libqpp INTERFACE -DUSE_OPENQASM2_SPECS=false)
endif ()

#### Use destructive measurements when executing OpenQASM 2.0 circuits
if (${USE_OPENQASM2_DESTRUCTIVE_MEASUREMENTS})
target_compile_definitions(libqpp INTERFACE -DUSE_OPENQASM2_DESTRUCTIVE_MEASUREMENTS=true)
else ()
target_compile_definitions(libqpp INTERFACE -DUSE_OPENQASM2_DESTRUCTIVE_MEASUREMENTS=false)
endif ()


#### Dependencies, do not modify unless you know what you're doing
if (${WITH_EXAMPLES} OR ${WITH_UNIT_TESTS})
include(cmake/qpp_dependencies.cmake)
Expand Down
14 changes: 10 additions & 4 deletions include/qasm/qasm.hpp
Expand Up @@ -514,9 +514,15 @@ class QCircuitBuilder final : public ast::Visitor {
auto c_args = var_access_as_creg(stmt.c_arg());
auto circuit = ctx.get_circuit();

// apply measurements non-desctructively
// apply measurements non-destructively (destructively if
// the CMake option USE_OPENQASM2_DESTRUCTIVE_MEASUREMENTS is ON
// (OFF by default))
bool is_destructive = false;
#if USE_OPENQASM2_DESTRUCTIVE_MEASUREMENTS
is_destructive = true;
#endif
for (idx i = 0; i < q_args.size(); i++) {
circuit->measureZ(q_args[i], c_args[i], false);
circuit->measureZ(q_args[i], c_args[i], is_destructive);
}
}

Expand Down Expand Up @@ -805,7 +811,7 @@ class QCircuitBuilder final : public ast::Visitor {
};

/**
* \brief Reads a OpenQASM circuit from stdin and returns its qpp::QCircuit
* \brief Reads an OpenQASM circuit from stdin and returns its qpp::QCircuit
* representation
*
* \return qpp::QCircuit
Expand All @@ -821,7 +827,7 @@ inline QCircuit read(std::istream& stream) {
}

/**
* \brief Reads a OpenQASM circuit from a file and returns its qpp::QCircuit
* \brief Reads an OpenQASM circuit from a file and returns its qpp::QCircuit
* representation
*
* \return qpp::QCircuit
Expand Down

0 comments on commit 2f7c7c8

Please sign in to comment.