Skip to content

Commit

Permalink
Added support for ClassicControlledOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
hillmich committed Jun 14, 2020
1 parent c04195b commit 4aca639
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion extern/googletest
Submodule googletest updated 62 files
+10 −18 .travis.yml
+1 −0 BUILD.bazel
+3 −3 README.md
+0 −1 ci/build-linux-bazel.sh
+2 −2 ci/env-linux.sh
+1 −1 ci/install-linux.sh
+5 −20 ci/travis.sh
+2 −0 googlemock/CMakeLists.txt
+16 −16 googlemock/README.md
+1 −1 googlemock/cmake/gmock.pc.in
+1 −1 googlemock/cmake/gmock_main.pc.in
+5 −0 googlemock/docs/cheat_sheet.md
+9 −0 googlemock/docs/community_created_documentation.md
+5 −5 googlemock/docs/cook_book.md
+2 −2 googlemock/docs/for_dummies.md
+1 −1 googlemock/docs/gmock_faq.md
+33 −40 googlemock/include/gmock/gmock-actions.h
+0 −75 googlemock/include/gmock/gmock-generated-actions.h
+0 −22 googlemock/include/gmock/gmock-generated-actions.h.pump
+38 −124 googlemock/include/gmock/gmock-matchers.h
+4 −5 googlemock/include/gmock/gmock-spec-builders.h
+6 −4 googlemock/include/gmock/internal/gmock-internal-utils.h
+3 −3 googlemock/include/gmock/internal/gmock-pp.h
+0 −2 googlemock/src/gmock-matchers.cc
+97 −32 googlemock/test/gmock-actions_test.cc
+0 −55 googlemock/test/gmock-generated-actions_test.cc
+36 −15 googlemock/test/gmock-matchers_test.cc
+2 −0 googletest/CMakeLists.txt
+1 −1 googletest/cmake/gtest_main.pc.in
+27 −10 googletest/docs/advanced.md
+0 −71 googletest/docs/pkgconfig.md
+1 −1 googletest/docs/primer.md
+2 −3 googletest/include/gtest/gtest-death-test.h
+12 −6 googletest/include/gtest/gtest-matchers.h
+94 −12 googletest/include/gtest/gtest-printers.h
+6 −3 googletest/include/gtest/gtest.h
+11 −6 googletest/include/gtest/internal/gtest-internal.h
+111 −7 googletest/include/gtest/internal/gtest-port.h
+21 −17 googletest/include/gtest/internal/gtest-type-util.h
+12 −24 googletest/src/gtest-filepath.cc
+4 −0 googletest/src/gtest-internal-inl.h
+1 −1 googletest/src/gtest-port.cc
+6 −0 googletest/src/gtest-printers.cc
+1 −11 googletest/src/gtest-typed-test.cc
+226 −66 googletest/src/gtest.cc
+7 −5 googletest/test/googletest-death-test-test.cc
+1 −1 googletest/test/googletest-death-test_ex_test.cc
+1 −0 googletest/test/googletest-env-var-test.py
+5 −0 googletest/test/googletest-env-var-test_.cc
+30 −4 googletest/test/googletest-json-output-unittest.py
+18 −6 googletest/test/googletest-output-test-golden-lin.txt
+0 −57 googletest/test/googletest-output-test_.cc
+6 −5 googletest/test/googletest-param-test-test.cc
+2 −4 googletest/test/googletest-port-test.cc
+179 −10 googletest/test/googletest-printers-test.cc
+4 −4 googletest/test/gtest-unittest-api_test.cc
+1 −0 googletest/test/gtest_help_test.py
+46 −3 googletest/test/gtest_unittest.cc
+2 −2 googletest/test/gtest_xml_outfiles_test.py
+39 −23 googletest/test/gtest_xml_output_unittest.py
+9 −0 googletest/test/gtest_xml_output_unittest_.cc
+2 −1 googletest/test/gtest_xml_test_utils.py
2 changes: 1 addition & 1 deletion extern/qfr
Submodule qfr updated from 27b60f to 86875f
21 changes: 16 additions & 5 deletions src/QFRSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ void QFRSimulator::Simulate() {

unsigned long op_num = 0;

std::map<unsigned int, bool> classic_values;
std::map<int, bool> classic_values;

for (auto& op : *qc) {
if (!op->isUnitary()) {
if(auto* nu_op = dynamic_cast<qc::NonUnitaryOperation*>(op.get())) {
if (nu_op->getName()[0] == 'M') {
if (op->isNonUnitaryOperation()) {
if (auto *nu_op = dynamic_cast<qc::NonUnitaryOperation *>(op.get())) {
if (nu_op->getName()[0] == 'M') { // Measure starts with 'M', quite hacky though
auto quantum = nu_op->getControls();
auto classic = nu_op->getTargets();

if(quantum.size() != classic.size()) {
if (quantum.size() != classic.size()) {
std::cerr << "[ERROR] Measurement: Sizes of quantum and classic register mismatch.\n";
std::exit(1);
}
Expand All @@ -40,6 +40,17 @@ void QFRSimulator::Simulate() {
}
dd->garbageCollect();
} else {
if (op->isClassicControlledOperation()) {
if (auto *cc_op = dynamic_cast<qc::ClassicControlledOperation *>(op.get())) {
auto classic_bit_index = static_cast<short>(cc_op->getParameter().at(0)); // fp -> short *argh*
if (!classic_values[classic_bit_index]) {
continue;
}
} else {
std::cerr << "[ERROR] Dynamic cast to ClassicControlledOperation failed." << std::endl;
std::exit(1);
}
}
//std::clog << "[INFO] op " << op_num++ << " is " << op->getName()
// << " #controls=" << op->getControls().size()
// << " statesize=" << dd->size(root_edge) << "\n";
Expand Down
16 changes: 16 additions & 0 deletions test/test_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ TEST(SimulatorTest, SingleOneQubitGateOnTwoQubitCircuit) {
ASSERT_EQ("01", m);
}

TEST(SimulatorTest, ClassicControlledOp) {
auto quantumComputation = std::make_unique<qc::QuantumComputation>(2);
quantumComputation->emplace_back<qc::StandardOperation>(2, 0, qc::X);
std::vector<unsigned short> qubit_to_measure = {0};
quantumComputation->emplace_back<qc::NonUnitaryOperation>(2, qubit_to_measure, qubit_to_measure);
std::unique_ptr<qc::Operation> op (new qc::StandardOperation(2, 1, qc::X));
quantumComputation->emplace_back<qc::ClassicControlledOperation>(op, 0);

QFRSimulator ddsim(quantumComputation);
ddsim.Simulate();

auto m = ddsim.MeasureAll(false);

ASSERT_EQ("11", m);
}


TEST(SimulatorTest, DestructiveMeasurementAll) {
auto quantumComputation = std::make_unique<qc::QuantumComputation>(2);
Expand Down

0 comments on commit 4aca639

Please sign in to comment.