Skip to content

State preparation after synthesis - #1891

Merged
annagrin merged 71 commits into
NVIDIA:mainfrom
annagrin:state-preparation-after-synthesis
Jul 19, 2024
Merged

annagrin merged 71 commits into
NVIDIA:mainfrom
annagrin:state-preparation-after-synthesis

Conversation

@annagrin

@annagrin annagrin commented Jul 5, 2024 •

Copy link
Copy Markdown
Contributor

Description

  • Add a State Preparation pass after synthesis to convert state data to quantum gates
  • Use LiftAlloc pass to convert array initialization into a global constant array
    • Add a few const prop patterns to const prop truncations and extensions
    • Make sure we handle cases of arrays created inside kernels and passed as parameters
  • Create global arrays with dense element attributes for arrays flowing into quake.init_state
    • Update LiftAlloc, QuakeSynthesis
    • Allows lowering the code to LLVM in scenarios with or without state prep
  • Unify common code, add helpers in intrinsics.cpp for global constant array creation for various types
  • Add tests

Towards: #1086

annagrin added 28 commits June 17, 2024 10:08
@github-actions

github-actions Bot commented Jul 5, 2024

Copy link
Copy Markdown

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

github-actions Bot pushed a commit that referenced this pull request Jul 5, 2024
github-actions Bot pushed a commit that referenced this pull request Jul 18, 2024
@annagrin

annagrin commented Jul 18, 2024 •

Copy link
Copy Markdown
Contributor Author

@boschmitt

#include <cudaq.h>
#include <iostream>

__qpu__ void test(std::vector<cudaq::complex> inState) {
  cudaq::qvector q1 = inState;
}

void printCounts(cudaq::sample_result &result) {
  std::vector<std::string> values{};
  for (auto &&[bits, counts] : result) {
    values.push_back(bits);
  }

  std::sort(values.begin(), values.end());
  for (auto &&bits : values) {
    // Reverse the bits so that the output is a binary number.
    std::reverse(bits.begin(), bits.end());
    std::cout << bits << '\n';
  }
}

void printState(const std::vector<cudaq::complex> &amplitudes) {
  std::cout << "state: (size: " << amplitudes.size() << ") { ";
  for (auto a : amplitudes)
    std::cout << a << ' ';
  std::cout << "}\n";
}

int main() {
  constexpr auto kNUM_QUBITS = 5u;
  for (auto n = 0u; n < kNUM_QUBITS; ++n) {
    const auto dimension = (1ULL << (n + 1));
    for (auto i = 0u; i < dimension; ++i) {
      std::vector<cudaq::complex> amplitudes(dimension, 0.);
      amplitudes[i] = 1.;
      printState(amplitudes);
      auto counts = cudaq::sample(test, amplitudes);
      printCounts(counts);
      std::cout << '\n';
    }
  }
}

Wow, looks like bug, thanks for finding it! I suspect this check is incorrect in

return emitOpError("initialize state vector must be power of 2, but is " +
, because the veq length is the number of qubits :)

The good news is that everything works if I remove it. I've added your code as a test and fixed the issue, thanks!

@github-actions

Copy link
Copy Markdown

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

github-actions Bot pushed a commit that referenced this pull request Jul 18, 2024

@boschmitt boschmitt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I focused the review in the state preparation algorithm. It looks good to me. I just left a couple of smaller comments. Great work!

It might be good to add at least one python test that uses a bigger state vector.

Co-authored-by: Bruno Schmitt <7152025+boschmitt@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

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

github-actions Bot pushed a commit that referenced this pull request Jul 18, 2024
@annagrin

Copy link
Copy Markdown
Contributor Author

I focused the review in the state preparation algorithm. It looks good to me. I just left a couple of smaller comments. Great work!

It might be good to add at least one python test that uses a bigger state vector.

done, thanks!

annagrin and others added 2 commits July 18, 2024 13:16
@github-actions

Copy link
Copy Markdown

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

github-actions Bot pushed a commit that referenced this pull request Jul 18, 2024
@khalatepradnya

Copy link
Copy Markdown
Collaborator

Great work, @annagrin ! 👏🏼

github-actions Bot pushed a commit that referenced this pull request Jul 18, 2024
@github-actions

Copy link
Copy Markdown

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

@annagrin annagrin closed this Jul 19, 2024
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 19, 2024
@bettinaheim bettinaheim added the release notes Changes need to be captured in the release notes label Jul 29, 2024
@bettinaheim bettinaheim added this to the release 0.8.0 milestone Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release notes Changes need to be captured in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants