Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Photonics get_state #2243

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
bac044c
Initial move to nvqir
Omar-ORCA Sep 20, 2024
cf5ce62
refactor
Omar-ORCA Sep 24, 2024
ce48351
Divide em and simulator
Omar-ORCA Sep 25, 2024
081fb31
First working version
Omar-ORCA Oct 1, 2024
54376f8
Fixed get_state c++
Omar-ORCA Oct 1, 2024
c9071da
Fix Python bindings
Omar-ORCA Oct 2, 2024
af95e79
Change executable name in photonics_tbi_get_state.spp
Omar-ORCA Oct 2, 2024
12c53a8
Revert "Add Clifford-only simulator (Stim) (#2193)" (#2206)
bmhowe23 Sep 12, 2024
b1f5b92
Add missing optimizations for translation to openqasm2 (#2197)
annagrin Sep 12, 2024
cc1acc1
Add `dep-analysis` pass (a.k.a. `features/qubit-mgmt`) (#2163)
bmhowe23 Sep 13, 2024
50850b2
Fix argument conversion issues (#2211)
annagrin Sep 17, 2024
027a5ee
Update simulators.rst (#2208)
mmvandieren Sep 19, 2024
e2fdbbd
Allow state synthesis for remote simulators (#2212)
annagrin Sep 19, 2024
ea19347
Fix flaky tests (#2221)
annagrin Sep 20, 2024
f6758b7
Disable tests using new argument synthesis for NVQC (#2224)
annagrin Sep 23, 2024
7c661ce
[Python] [photonics] Enable 'get_state' API (#2201)
khalatepradnya Sep 25, 2024
2a43052
fixing path to conda.io python env (#2230)
sacpis Sep 26, 2024
d005f25
Publishing pipeline fixes after PR#2201 (#2229)
khalatepradnya Sep 26, 2024
75675d8
Fix exp_pauli issues on remote simulators and quantum devices (#2226)
annagrin Sep 30, 2024
7554a3d
Noise model enhancements (#2168)
1tnguyen Sep 30, 2024
e2eca68
[core] Separate compilation, supporting C++ host side function refere…
schweitzpgi Oct 1, 2024
f57cc30
Use the standard C++ file banner. (#2234)
schweitzpgi Oct 1, 2024
c01d227
Add Clifford-only simulator (Stim) (#2235)
bmhowe23 Oct 1, 2024
adf22b0
[custom op] Two-qubit operation synthesis (#2217)
khalatepradnya Oct 1, 2024
b8ad51a
[C++ bridge] Add support for std::vector::data method. (#2241)
schweitzpgi Oct 1, 2024
c326a85
Python formatting
Omar-ORCA Oct 3, 2024
2b4aa48
Revert "Python formatting" since it it inconsistent with other files.
khalatepradnya Oct 3, 2024
898004c
* Code formatting
khalatepradnya Oct 3, 2024
f29897d
* Consistent 'compile and run' comment
khalatepradnya Oct 3, 2024
aab9d6f
* No banner in examples
khalatepradnya Oct 3, 2024
36de665
Fix having more than one `sample` or `get_state` operation in a script
Omar-ORCA Oct 4, 2024
8c2dbdb
Use the = <init-expr>; style for photonics examples
Omar-ORCA Oct 4, 2024
4c8b510
Reformat a comment. (#2239)
schweitzpgi Oct 3, 2024
e834fcf
Update NVQC testing deployment spec (#2248)
bmhowe23 Oct 3, 2024
37b428b
Renaming qkernel_ref to qkernel per the spec. (#2253)
schweitzpgi Oct 4, 2024
366ed1e
* Fix 2 out of 3 build errors.
khalatepradnya Oct 4, 2024
b5e63e8
[C++ bridge] Add support for move constructor of std::vector. (#2236)
schweitzpgi Oct 4, 2024
41cc17e
clarifying the document text (#2247)
sacpis Oct 4, 2024
97d5f3b
updating spec (#2255)
sacpis Oct 5, 2024
f1cd9fc
Fix PhotonicsTester
Omar-ORCA Oct 7, 2024
bbbb919
Formatting
Omar-ORCA Oct 7, 2024
5dfa62b
Add enumerated noise_model_type to noise interface (#2200)
bmhowe23 Oct 7, 2024
5a91961
ORCA asynchronous sampling (#2205)
Omar-ORCA Oct 8, 2024
b5ad42a
Fix clang build
Omar-ORCA Oct 8, 2024
d4a83f8
Allow controlled Z gates for profile-specific QIR (#2245)
bmhowe23 Oct 8, 2024
fe2ab46
[core] Add quantum reference product type (#2254)
schweitzpgi Oct 8, 2024
b80fb40
* Restore the configuration for execution manager in the photnic
khalatepradnya Oct 8, 2024
095d2dd
* Restore unedited file.
khalatepradnya Oct 8, 2024
4e78361
* Doxygen fix
khalatepradnya Oct 8, 2024
a3f5c7d
Remove set_photonic_random_seed
Omar-ORCA Oct 9, 2024
32b3c6f
Return 0 from main in examples
Omar-ORCA Oct 9, 2024
d6947ea
Add multi-QPU support for the 'orca' target (#2260)
khalatepradnya Oct 9, 2024
fe423bf
* Code formatting
khalatepradnya Oct 9, 2024
2770546
* Addressing review comment - use `cudaq::linspace` API in C++ examples
khalatepradnya Oct 9, 2024
2595c17
* Addressing review comment - use `cudaq::linspace` API in C++ examples;
khalatepradnya Oct 9, 2024
2fba5ca
* Addressing review comment - remove superfluous 'else' after 'return'
khalatepradnya Oct 9, 2024
38510d5
Random walk phase estimation example in Python #1579 (#2060)
Gaurang-Belekar Oct 9, 2024
6eb87a4
Fixes a bug with separate compilation. (#2264)
schweitzpgi Oct 10, 2024
6eda1f0
Added new gates
Omar-ORCA Oct 10, 2024
b836772
Use the same parameters in the examples
Omar-ORCA Oct 10, 2024
fdcf7e9
Document photonics operations
Omar-ORCA Oct 10, 2024
492e995
Fix photonics_tbi_get_state.py
Omar-ORCA Oct 11, 2024
6fc6258
DCO Remediation Commit for Pradnya Khalate <148914294+khalatepradnya@…
khalatepradnya Oct 11, 2024
e77b172
DCO Remediation Commit for Ben Howe <[email protected]
khalatepradnya Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ env:
NGC_QUANTUM_TEAM: cuda-quantum
NVQC_FUNCTION_ID: 3bfa0342-7d2a-4f1b-8e81-b6608d28ca7d
# <Backend>:<GPU Type>:<Instance Type>:<Min Instances>:<Max Instances>
NGC_NVQC_DEPLOYMENT_SPEC: GFN:L40:gl40_1.br20_2xlarge:1:1
NGC_NVQC_DEPLOYMENT_SPEC: GFN:L40S:gl40s_1.br25_2xlarge:1:1
# If vars below are changed, it is recommended to also update the
# workflow_dispatch defaults above so they stay in sync.
cudaq_test_image: nvcr.io/nvidia/nightly/cuda-quantum:latest
Expand Down Expand Up @@ -490,7 +490,7 @@ jobs:
export ORCA_ACCESS_URL='${{ secrets.ORCA_ACCESS_URL }}'
set +e # Allow script to keep going through errors
test_err_sum=0
cpp_tests="docs/sphinx/examples/cpp/providers/orca.cpp"
cpp_tests="docs/sphinx/examples/cpp/providers/orca.cpp docs/sphinx/examples/cpp/providers/orca_mqpu.cpp"
for filename in $cpp_tests; do
[ -e "$filename" ] || echo "::error::Couldn't find file ($filename)"
nvq++ --target orca --orca-url $ORCA_ACCESS_URL $filename
Expand All @@ -509,7 +509,7 @@ jobs:
test_err_sum=$((test_err_sum+1))
fi
done
python_tests="docs/sphinx/examples/python/providers/orca.py"
python_tests="docs/sphinx/examples/python/providers/orca.py docs/sphinx/examples/python/providers/orca_mqpu.py"
for filename in $python_tests; do
[ -e "$filename" ] || echo "::error::Couldn't find file ($filename)"
python3 $filename 1> /dev/null
Expand Down Expand Up @@ -607,8 +607,8 @@ jobs:
for filename in `find targettests/Remote-Sim -name '*.cpp'`; do
# unsupport_args and compile_errors are compile error tests
# nested_vectors: Compiler fails to synthesize nested vector parameters (https://github.com/NVIDIA/cuda-quantum/issues/2001)
# state_init: New argument synthesis is not executed for nvqc (https://github.com/NVIDIA/cuda-quantum/issues/2146)
if [[ "$filename" != *"unsupport_args"* ]] && [[ "$filename" != *"compile_errors"* ]] && [[ "$filename" != *"nested_vectors"* ]] && [[ "$filename" != *"qvector_init_from_state"* ]]; then
# qvector_init_from_state, qvector_init_from_state_lazy, test_trotter: New argument synthesis is not executed for nvqc (https://github.com/NVIDIA/cuda-quantum/issues/2146)
if [[ "$filename" != *"unsupport_args"* ]] && [[ "$filename" != *"compile_errors"* ]] && [[ "$filename" != *"nested_vectors"* ]] && [[ "$filename" != *"qvector_init_from_state"* ]] && [[ "$filename" != *"qvector_init_from_state_lazy"* ]] && [[ "$filename" != *"test_trotter"* ]]; then
echo "$filename"
nvqc_config=""
# Look for a --remote-mqpu-auto-launch to determine the number of QPUs
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/nvqc_regression_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ jobs:
# nested_vectors: related to vector of pauli_words (https://github.com/NVIDIA/cuda-quantum/issues/1957)
# custom_operation: https://github.com/NVIDIA/cuda-quantum/issues/1985
# return_values: only supported in 0.8 NVQC service.
# state_init: only supported in 0.8 NVQC service.
if [[ "$filename" != *"unsupport_args"* ]] && [[ "$filename" != *"state_overlap"* ]] && [[ "$filename" != *"compile_errors"* ]] && [[ "$filename" != *"nested_vectors"* ]] && [[ "$filename" != *"pauli_word"* ]] && [[ "$filename" != *"custom_operation"* ]] && [[ "$filename" != *"return_values"* ]] && [[ "$filename" != *"qvector_init_from_state"* ]] && [[ "$filename" != *"qvector_init_from_vector"* ]]; then
# qvector_init_from_vector: only supported in 0.8 NVQC service.
# qvector_init_from_state, qvector_init_from_state_lazy, test_trotter: not supported yet on nvqc: https://github.com/NVIDIA/cuda-quantum/issues/2146
if [[ "$filename" != *"unsupport_args"* ]] && [[ "$filename" != *"state_overlap"* ]] && [[ "$filename" != *"compile_errors"* ]] && [[ "$filename" != *"nested_vectors"* ]] && [[ "$filename" != *"pauli_word"* ]] && [[ "$filename" != *"custom_operation"* ]] && [[ "$filename" != *"return_values"* ]] && [[ "$filename" != *"qvector_init_from_state"* ]] && [[ "$filename" != *"qvector_init_from_state_lazy"* ]] && [[ "$filename" != *"qvector_init_from_vector"* ]] && [[ "$filename" != *"test_trotter"* ]]; then
echo "$filename"
nvqc_config=""
# Look for a --remote-mqpu-auto-launch to determine the number of QPUs
Expand Down
7 changes: 7 additions & 0 deletions cmake/Modules/CUDAQConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ add_library(cudaq::cudaq-qpp-density-matrix-cpu-target SHARED IMPORTED)
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-dm${CMAKE_SHARED_LIBRARY_SUFFIX}"
IMPORTED_SONAME "libnvqir-dm${CMAKE_SHARED_LIBRARY_SUFFIX}"
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-default")

# QPP photonics Target
add_library(cudaq::cudaq-photonics-cpu-target SHARED IMPORTED)
set_target_properties(cudaq::cudaq-photonics-cpu-target PROPERTIES
IMPORTED_LOCATION "${CUDAQ_LIBRARY_DIR}/libnvqir-photonics${CMAKE_SHARED_LIBRARY_SUFFIX}"
IMPORTED_SONAME "libnvqir-photonics${CMAKE_SHARED_LIBRARY_SUFFIX}"
IMPORTED_LINK_INTERFACE_LIBRARIES "cudaq::cudaq-platform-default;cudaq::cudaq-em-photonics")
# -------------------------

if(NOT TARGET cudaq::cudaq)
Expand Down
3 changes: 2 additions & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if (CUSTATEVEC_ROOT AND CUDA_FOUND)
endif()
endif()

add_nvqpp_test(photonics_sim providers/photonics.cpp TARGET photonics)
add_nvqpp_test(photonics_sim providers/photonics.cpp TARGET photonics-cpu)
add_nvqpp_test(SampleAsyncRemote using/cudaq/platform/sample_async_remote.cpp TARGET remote-mqpu SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/snippets/cpp)
set_tests_properties(
nvqpp_SampleAsyncRemote
Expand Down Expand Up @@ -141,6 +141,7 @@ if (CUDAQ_ENABLE_PYTHON)
add_pycudaq_test(DepolarizingNoise noise_depolarization.py)
add_pycudaq_test(PhaseFlipNoise noise_phase_flip.py)
add_pycudaq_test(KrausNoise noise_kraus_operator.py)
add_pycudaq_test(NoiseCallback noise_callback.py)

if (CUTENSORNET_ROOT AND CUDA_FOUND)
# This example uses tensornet backend.
Expand Down
66 changes: 54 additions & 12 deletions docs/sphinx/api/default_ops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -638,31 +638,67 @@ operations, each operating on 2 qubits.
Photonic Operations on Qudits
=============================

These operations are valid only on the `photonics` target which does not support the quantum operations above.
These operations are valid only on the `photonics-cpu` target which does not support
the quantum operations above.

:code:`plus`
:code:`create`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Is this a new gate? or an alias for 'plus'? Doesn't match the examples and API spec...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a new gate replacing the plus that can be deprecated, the behaviour of the plus gate is not very intuitive (cycling through the number of photons).

---------------------

This is a place-holder, to be updated later.
This operation increments the number of photons in a qumode up to a maximum value
defined by the qudit level that represents the qumode. If it is applied to a qumode
where the number of photons is already at the maximum value, the operation has no
effect.

:math:`U|0\rangle → |1\rangle, U|1\rangle → |2\rangle, U|2\rangle → |3\rangle, \cdots, U|d\rangle → |d\rangle`
where :math:`d` is the qudit level.

.. tab:: Python

.. code-block:: python

q = qudit(3)
plus(q)
create(q)

.. tab:: C++

.. code-block:: cpp

cudaq::qvector<3> q(1);
plus(q[0]);
create(q[0]);

:code:`annihilate`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

---------------------

This operation reduces the number of photons in a qumode up to a minimum value of
0 representing the vacuum state. If it is applied to a qumode where the number of
photons is already at the minimum value 0, the operation has no effect.

:math:`U|0\rangle → |0\rangle, U|1\rangle → |0\rangle, U|2\rangle → |1\rangle, \cdots, U|d\rangle → |d-1\rangle`
where :math:`d` is the qudit level.

.. tab:: Python

.. code-block:: python

q = qudit(3)
annihilate(q)

.. tab:: C++

.. code-block:: cpp

cudaq::qvector<3> q(1);
annihilate(q[0]);

:code:`phase_shift`
---------------------

This is a place-holder, to be updated later.
A phase shifter adds a phase :math:`\phi` on a qumode. For the annihilation (:math:`a_1`)
and creation operators (:math:`a_1^\dagger`) of a qumode, the phase shift operator
is defined by

.. math::
P(\phi) = \exp\left(i \phi a_1^\dagger a_1 \right)

.. tab:: Python

Expand All @@ -681,7 +717,13 @@ This is a place-holder, to be updated later.
:code:`beam_splitter`
---------------------

This is a place-holder, to be updated later.
Beam splitters act on two qumodes together and it is parametrized by a single angle
:math:`\theta`, relating to reflectivity.
For the annihilation (:math:`a_1` and :math:`a_2`) and creation operators (:math:`a_1^\dagger`
and :math:`a_2^\dagger`) of two qumodes, the beam splitter operator is defined by

.. math::
B(\theta) = \exp\left[i \theta (a_1^\dagger a_2 + a_1 a_2^\dagger) \right]

.. tab:: Python

Expand All @@ -700,19 +742,19 @@ This is a place-holder, to be updated later.
:code:`mz`
---------------------

This operation returns the measurement results of the input qudit(s).
This operation returns the measurement results of the input qumode(s).

.. tab:: Python

.. code-block:: python

qutrits = [qudit(3) for _ in range(2)]
mz(qutrits)
qumodes = [qudit(3) for _ in range(2)]
mz(qumodes)


.. tab:: C++

.. code-block:: cpp

cudaq::qvector<3> qutrits(2);
mz(qutrits);
cudaq::qvector<3> qumodes(2);
mz(qumodes);
16 changes: 13 additions & 3 deletions docs/sphinx/api/languages/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Common
.. doxygenclass:: cudaq::async_result
:members:

.. doxygentypedef:: async_sample_result


.. doxygenstruct:: cudaq::ExecutionResult
:members:
Expand Down Expand Up @@ -74,6 +76,8 @@ Common

.. doxygenclass:: cudaq::RemoteSimulationState

.. doxygenstruct:: cudaq::PhotonicState

.. doxygenclass:: cudaq::registry::RegisteredType
:members:

Expand Down Expand Up @@ -115,6 +119,8 @@ Noise Modeling
.. doxygenclass:: cudaq::noise_model
:members:

.. doxygenenum:: cudaq::noise_model_type

Kernel Builder
===============

Expand Down Expand Up @@ -166,7 +172,9 @@ Platform

.. doxygenclass:: cudaq::BaseRemoteSimulatorQPU

.. doxygenclass:: cudaq::BaseNvcfSimulatorQPU
.. doxygenclass:: cudaq::BaseNvcfSimulatorQPU

.. doxygenclass:: cudaq::OrcaRemoteRESTQPU

.. doxygenclass:: cudaq::quantum_platform
:members:
Expand Down Expand Up @@ -229,5 +237,7 @@ Namespaces
.. doxygennamespace:: cudaq::orca
:desc-only:

.. doxygenfunction:: cudaq::orca::sample(std::vector<std::size_t> &input_state, std::vector<std::size_t> &loop_lengths, std::vector<double> &bs_angles, int n_samples = 10000)
.. doxygenfunction:: cudaq::orca::sample(std::vector<std::size_t> &input_state, std::vector<std::size_t> &loop_lengths, std::vector<double> &bs_angles, std::vector<double> &ps_angles, int n_samples = 10000)
.. doxygenfunction:: cudaq::orca::sample(std::vector<std::size_t> &input_state, std::vector<std::size_t> &loop_lengths, std::vector<double> &bs_angles, int n_samples = 10000, std::size_t qpu_id = 0)
.. doxygenfunction:: cudaq::orca::sample(std::vector<std::size_t> &input_state, std::vector<std::size_t> &loop_lengths, std::vector<double> &bs_angles, std::vector<double> &ps_angles, int n_samples = 10000, std::size_t qpu_id = 0)
.. doxygenfunction:: cudaq::orca::sample_async(std::vector<std::size_t> &input_state, std::vector<std::size_t> &loop_lengths, std::vector<double> &bs_angles, int n_samples = 10000, std::size_t qpu_id = 0)
.. doxygenfunction:: cudaq::orca::sample_async(std::vector<std::size_t> &input_state, std::vector<std::size_t> &loop_lengths, std::vector<double> &bs_angles, std::vector<double> &ps_angles, int n_samples = 10000, std::size_t qpu_id = 0)
67 changes: 67 additions & 0 deletions docs/sphinx/examples/cpp/basics/noise_callback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Compile and run with:
// ```
// nvq++ noise_callback.cpp --target density-matrix-cpu -o dyn.x
// && ./dyn.x
// ```
//
// Note: You must set the target to a density matrix backend for the noise
// to successfully impact the system.

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

// CUDA-Q supports several different models of noise. In this
// case, we will examine the dynamic noise channel specified as a callback
// function.

int main() {

// We will begin by defining an empty noise model that we will add
// our channel to.
cudaq::noise_model noise;
// Noise model callback function
const auto rx_noise = [](const auto &qubits,
const auto &params) -> cudaq::kraus_channel {
// Model a pulse-length based rotation gate:
// the bigger the angle, the longer the pulse, i.e., more amplitude damping.
auto angle = params[0];
// Normalize the angle into the [0, 2*pi] range
while (angle > 2. * M_PI)
angle -= 2. * M_PI;

while (angle < 0)
angle += 2. * M_PI;
// Damping rate is linearly proportional to the angle
const auto damping_rate = angle / (2. * M_PI);
std::cout << "Angle = " << params[0]
<< ", amplitude damping rate = " << damping_rate << "\n";
return cudaq::amplitude_damping_channel(damping_rate);
};

// Bind the noise model callback function to the `rx` gate
noise.add_channel<cudaq::types::rx>(rx_noise);

auto kernel = [](double angle) __qpu__ {
cudaq::qubit q;
rx(angle, q);
mz(q);
};

// Now let's set the noise and we're ready to run the simulation!
cudaq::set_noise(noise);

// Our results should show measurements in both the |0> and |1> states,
// indicating that the noise has successfully impacted the system. Note: a
// `rx(pi)` is equivalent to a Pauli X gate, and thus, it should be in the |1>
// state if no noise is present.
auto noisy_counts = cudaq::sample(kernel, M_PI);
std::cout << "Noisy result:\n";
noisy_counts.dump();

// To confirm this, we can run the simulation again without noise.
cudaq::unset_noise();
auto noiseless_counts = cudaq::sample(kernel, M_PI);
std::cout << "Noiseless result:\n";
noiseless_counts.dump();
return 0;
}
5 changes: 3 additions & 2 deletions docs/sphinx/examples/cpp/other/trotter_kernel_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ int SPINS = 11; // set to around 25 qubits for `nvidia` target
int STEPS = 10; // set to around 100 for `nvidia` target

// Compile and run with:
// clang-format off
// ```
// nvq++ --enable-mlir -v trotter_kernel_mode.cpp -o trotter.x -target nvidia &&
// ./trotter.x
// nvq++ --enable-mlir -v trotter_kernel_mode.cpp -o trotter.x --target nvidia && ./trotter.x
// ```
// clang-format off

// Alternating up/down spins
struct initState {
Expand Down
Loading
Loading