KEMBAR78
Adding photonics execution manager by Omar-ORCA · Pull Request #515 · NVIDIA/cuda-quantum · GitHub
Skip to content

Conversation

@Omar-ORCA
Copy link
Contributor

@Omar-ORCA Omar-ORCA commented Aug 1, 2023

Checklist:

  • I have added tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Description

The photonics execution manager uses qudits to model linear optical, quantum photonic circuits.
Several gates are implemented that can be used to simulate programmable time-bin interferometers.

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

CLA Assistant Lite bot All Contributors have signed the CLA.

@Omar-ORCA
Copy link
Contributor Author

I have read the Contributor License Agreement and I hereby accept the Terms.

@Omar-ORCA
Copy link
Contributor Author

Omar-ORCA commented Aug 1, 2023

recheck

@amccaskey
Copy link
Collaborator

Hey Omar, would the following work for you to hook into the sample_result return on cudaq::sample?

diff --git a/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp b/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp
index 41eb14e..3400c46 100644
--- a/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp
+++ b/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp
@@ -63,9 +63,22 @@ protected:
       auto sampleResult =
           qpp::sample(1000000, state, ids, sampleQudits.begin()->levels);
 
+      cudaq::ExecutionResult counts;
       for (auto [result, count] : sampleResult) {
         std::cout << fmt::format("Sample {} : {}", result, count) << "\n";
+        std::stringstream bitstring;
+        for (const auto &quditRes : result) {
+          bitstring << quditRes;
+        }
+
+        // Add to the sample result
+        // in mid-circ sampling mode this will append 1 bitstring
+        counts.appendResult(bitstring.str(), count);
+        // Reset the state.
+        bitstring.str("");
+        bitstring.clear();
       }
+      executionContext->result.append(counts);
     }
   }

diff --git a/unittests/photonics/PhotonicsTester.cpp b/unittests/photonics/PhotonicsTester.cpp
index cb4dae0..5dde414 100644
--- a/unittests/photonics/PhotonicsTester.cpp
+++ b/unittests/photonics/PhotonicsTester.cpp
@@ -37,5 +37,9 @@ TEST(PhotonicsTester, checkSimple) {
   EXPECT_EQ(res[0], 1);
   EXPECT_EQ(res[1], 2);
 
-  cudaq::sample(test2{});
+  auto counts = cudaq::sample(test2{});
+
+  for (auto&[k,v]: counts) {
+    printf("Result / Count = %s : %lu\n", k.c_str(), v);
+  }
 }

@Omar-ORCA
Copy link
Contributor Author

Hey Omar, would the following work for you to hook into the sample_result return on cudaq::sample?

diff --git a/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp b/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp
index 41eb14e..3400c46 100644
--- a/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp
+++ b/runtime/cudaq/qis/managers/photonics/PhotonicsExecutionManager.cpp
@@ -63,9 +63,22 @@ protected:
       auto sampleResult =
           qpp::sample(1000000, state, ids, sampleQudits.begin()->levels);
 
+      cudaq::ExecutionResult counts;
       for (auto [result, count] : sampleResult) {
         std::cout << fmt::format("Sample {} : {}", result, count) << "\n";
+        std::stringstream bitstring;
+        for (const auto &quditRes : result) {
+          bitstring << quditRes;
+        }
+
+        // Add to the sample result
+        // in mid-circ sampling mode this will append 1 bitstring
+        counts.appendResult(bitstring.str(), count);
+        // Reset the state.
+        bitstring.str("");
+        bitstring.clear();
       }
+      executionContext->result.append(counts);
     }
   }

diff --git a/unittests/photonics/PhotonicsTester.cpp b/unittests/photonics/PhotonicsTester.cpp
index cb4dae0..5dde414 100644
--- a/unittests/photonics/PhotonicsTester.cpp
+++ b/unittests/photonics/PhotonicsTester.cpp
@@ -37,5 +37,9 @@ TEST(PhotonicsTester, checkSimple) {
   EXPECT_EQ(res[0], 1);
   EXPECT_EQ(res[1], 2);
 
-  cudaq::sample(test2{});
+  auto counts = cudaq::sample(test2{});
+
+  for (auto&[k,v]: counts) {
+    printf("Result / Count = %s : %lu\n", k.c_str(), v);
+  }
 }

That worked 👍

@copy-pr-bot
Copy link

copy-pr-bot bot commented Sep 14, 2023

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@amccaskey
Copy link
Collaborator

amccaskey commented Sep 14, 2023

/ok to test

Command Bot: Processing...

Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 14, 2023
@amccaskey
Copy link
Collaborator

amccaskey commented Sep 14, 2023

/ok to test

Command Bot: Processing...

@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 14, 2023
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 15, 2023
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 15, 2023
Signed-off-by: Alex McCaskey <amccaskey@nvidia.com>
@amccaskey
Copy link
Collaborator

amccaskey commented Sep 18, 2023

/ok to test

Command Bot: Processing...

@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 18, 2023
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 18, 2023
@amccaskey
Copy link
Collaborator

amccaskey commented Oct 9, 2023

/ok to test

Command Bot: Processing...

@amccaskey
Copy link
Collaborator

amccaskey commented Oct 10, 2023

/ok to test

Command Bot: Processing...

@bmhowe23
Copy link
Collaborator

bmhowe23 commented Oct 19, 2023

/ok to test

Command Bot: Processing...

@bmhowe23 bmhowe23 enabled auto-merge (squash) October 19, 2023 11:41
@bmhowe23 bmhowe23 merged commit cb26478 into NVIDIA:main Oct 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2023
@bettinaheim bettinaheim added the enhancement New feature or request label Nov 15, 2023
@bettinaheim bettinaheim added this to the release 0.5.0 milestone Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants