Skip to content

Commit

Permalink
Fermioniq implementation (#2225)
Browse files Browse the repository at this point in the history
* Allow state synthesis for remote simulators (#2212)

* Copy pointer arguments for lazy evaluation on remote simulators

Signed-off-by: Markus Pfundstein <[email protected]>

* Fix flaky tests (#2221)

* Fix flaky tests

Signed-off-by: Markus Pfundstein <[email protected]>

* fermioniq

Signed-off-by: Markus Pfundstein <[email protected]>

* added user_data

Signed-off-by: Markus Pfundstein <[email protected]>

* fermioniq provider example

Signed-off-by: Markus Pfundstein <[email protected]>

* updated call

Signed-off-by: Markus Pfundstein <[email protected]>

* fermioniq passes

Signed-off-by: Markus Pfundstein <[email protected]>

* fixed merge to main

Signed-off-by: Markus Pfundstein <[email protected]>

* fix

Signed-off-by: Markus Pfundstein <[email protected]>

* removed unnecessary changes from main

Signed-off-by: Markus Pfundstein <[email protected]>

* easier Fermionq QPU

Signed-off-by: Markus Pfundstein <[email protected]>

* ServerHelper now separate shared lib

Signed-off-by: Markus Pfundstein <[email protected]>

* Fermioniq working in python

Signed-off-by: Markus Pfundstein <[email protected]>

* Fermioniq working in python

Signed-off-by: Markus Pfundstein <[email protected]>

* Disable tests using new argument synthesis for NVQC (#2224)

* Remove test_trotter.cpp until nvqc with new synthesis is working

* Disable test_trotter.cpp for nvqc

* Disable more state tests for nvqc

Signed-off-by: Markus Pfundstein <[email protected]>

* [Python] [photonics] Enable 'get_state' API  (#2201)

Signed-off-by: Markus Pfundstein <[email protected]>

* fixing path to conda.io python env (#2230)

Signed-off-by: Markus Pfundstein <[email protected]>

* Publishing pipeline fixes after PR#2201 (#2229)

Signed-off-by: Markus Pfundstein <[email protected]>

* Fix exp_pauli issues on remote simulators and quantum devices (#2226)

* Made exp_pauli work on quantum devices and remote sim

* Add more tests

* Address CR comments

Signed-off-by: Markus Pfundstein <[email protected]>

* Noise model enhancements (#2168)

* Some prototyping code

* Prototype

* Revise the noise model

* Add example

* Update docstring:

* Code refactor

* Add tests

* Code format

* Add Python tests

* Code format

* Support custom op

- For the path via ExecutionManager: making sure the registration is
  early enough, i.e., at the point of registration.

- For the Python path: need to let the registry know about the
  registration.

- Propagate the custom op name all the way to the simulator.

* Fix a lit test

* Add docs

* Fix remote test

* Fix spelling

* Add a C++ example

Signed-off-by: Markus Pfundstein <[email protected]>

* [core] Separate compilation, supporting C++ host side function references. (#2216)

* [core] Separate compilation, supporting C++ host side function references.

These changes add a new wrapper class to support interfacing between
kernels. Kernels on the device side have their own names and calling
conventions. Meanwhile, the C++ host code can capture references to
these kernels. The C++ compiler assumes it can erase the functions
completely and degenerate any reference to them as a pointer.
Furthermore, it may inline or wrap this code in a thicket of template
instantiations. But in order to be useful on the device side, the CUDA-Q
runtime must be able to determine which kernel was wrapped in C++ code,
lookup the device side code, and "link-time" optimize these calls, doing
calling convention conversions, etc. Furthermore, what must be done is
flavored by the execution environment.

* Update the call paths of hybridLaunchKernel so that we can use the new
argument synthesis instead of falling back on and failing with quake
synthesis.

* Fix check lines.

* More check line fixes.

* Remove stale comment.

* Add another deduction guide test (when using cudaq::sample). Mark all
tests that use deduction guides as C++ 20 (since C++ 17 doesn't have
guides).

* Add a hacky workaround for python. Python needs to use the new argument
synthesis, but it is still using the old quake synthesis compiler pass.

* CI whining about formatting.

* Remove XFAIL from state_preparation_vector.cpp

* Add split-file to installed stuff.

* Add tests.

* Add guards to tests since some phases of the CI don't have the necessary
test utilities properly installed.

* Mark failing state tests as UNSUPPORTED for now. These should be fixed
when the state handling using new argument synthesis is fully
implemented.

* Fix bug when there are multiple callables.

* Review comment about include iostream.

* Fix unsupported line syntax.

Signed-off-by: Markus Pfundstein <[email protected]>

* Use the standard C++ file banner. (#2234)

Signed-off-by: Markus Pfundstein <[email protected]>

* Add Clifford-only simulator (Stim) (#2235)

* Add Clifford-only simulator (Stim) (#2193)

* Constrain x86-64 build to AVX2

* Compilation update for #2168

---------

Co-authored-by: Thien Nguyen <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* [custom op] Two-qubit operation synthesis (#2217)

* Added failing test(s)
* Skeleton for a new decomposer class
* Random Python tests
* Using QZ decomposition
* Clean up
* Qubit ordering fixes
* Fixing the exp_pauli decomposition
* Refactor one-qubit decomposer to use eigen matrix
* Increase tolerance to check for unitary
* Use CHECK-DAG in lit tests, also less precision for angles
* Code comments
* Added failing test(s) for 3q custom operation decomposition.
* Extend the C++ 2q test to all supported hardware targets.

---------

Co-authored-by: Thien Nguyen <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* [C++ bridge] Add support for std::vector::data method. (#2241)

* [C++ bridge] Add support for std::vector::data method.

* clang-format

* Fix check line to account for location.

Signed-off-by: Markus Pfundstein <[email protected]>

* Reformat a comment. (#2239)

Signed-off-by: Markus Pfundstein <[email protected]>

* Update NVQC testing deployment spec (#2248)

Signed-off-by: Markus Pfundstein <[email protected]>

* Renaming qkernel_ref to qkernel per the spec. (#2253)

* Remove anyon target test. It's nondeterministic. See #2249.

* Rename qkernel_ref to qkernel as per the latest spec.

Signed-off-by: Markus Pfundstein <[email protected]>

* [C++ bridge] Add support for move constructor of std::vector. (#2236)

* [C++ bridge] Add support for move constructor of std::vector.

Allow the use of the move constructor so that cases such as

	std::vector<int> vectorValue(N);
	...
	return vectorValue;

will compile and simple vectors of arithmetic types may be used.  Note
that this requires the CUDA-Q runtime to actually return these values to
the caller rather than dropping them on the floor after a launched
kernel has deactivated.  That is not always the case, however, since
some launchers do not expect any return value(s).

Extend GKE to deal with calls since inlining may not have happened.

We introduced a bug when we changed when inlining was done in the
pipeline.

* Update test.

Signed-off-by: Markus Pfundstein <[email protected]>

* clarifying the document text (#2247)

Signed-off-by: Markus Pfundstein <[email protected]>

* updating spec (#2255)

Signed-off-by: Markus Pfundstein <[email protected]>

* merged upstream main into branch

Signed-off-by: Markus Pfundstein <[email protected]>

* extracted PyFermioniq into separate file

Signed-off-by: Markus Pfundstein <[email protected]>

* added {F,f}ermioniq to spelling allowlist

Signed-off-by: Markus Pfundstein <[email protected]>

* linter

Signed-off-by: Markus Pfundstein <[email protected]>

* sorted allowlist

Signed-off-by: Markus Pfundstein <[email protected]>

* sorted allowlist

Signed-off-by: Markus Pfundstein <[email protected]>

* linter

Signed-off-by: Markus Pfundstein <[email protected]>

* latest submod

Signed-off-by: Markus Pfundstein <[email protected]>

* reuse lowerQuakeCode instead of own implementation

Signed-off-by: Markus Pfundstein <[email protected]>

* Add enumerated noise_model_type to noise interface (#2200)

Signed-off-by: Markus Pfundstein <[email protected]>

* ORCA asynchronous sampling (#2205)

Support for asynchronous sampling for ORCA backend

---------

Co-authored-by: Pradnya Khalate <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* Allow controlled Z gates for profile-specific QIR (#2245)

Signed-off-by: Markus Pfundstein <[email protected]>

* Revert "latest submod"

This reverts commit c293db9.

Signed-off-by: Markus Pfundstein <[email protected]>

* removed v2 flag from chrono

Signed-off-by: Markus Pfundstein <[email protected]>

* add fermioniq to ignore list

Signed-off-by: Markus Pfundstein <[email protected]>

* added FermioniqQPU class as registered type

Signed-off-by: Markus Pfundstein <[email protected]>

* [core] Add quantum reference product type (#2254)

* Start on pure quantum struct usage in kernels

Signed-off-by: Alex McCaskey <[email protected]>

* Update the python bindings with new qstruct restrictions

Signed-off-by: Alex McCaskey <[email protected]>

* Enable default parenthesis constructor

Signed-off-by: Alex McCaskey <[email protected]>

* disallow recursive quantum struct

Signed-off-by: Alex McCaskey <[email protected]>

* Implement error handling for various cases in python

Signed-off-by: Alex McCaskey <[email protected]>

* spell fixes

Signed-off-by: Alex McCaskey <[email protected]>

* forgot to filter out __qpu__ methods on structs, those are allowed

Signed-off-by: Alex McCaskey <[email protected]>

* Add new quantum reference type, !quake.struq, and a couple of new
operations: quake.make_struq and quake.get_member.  These add the
utility of having a product quantum reference type (to logically group
together sets of qubits) but keep the classical and quantum dialects
distinct.

Update the tests, python ast bridge, C++ bridge, add codegen patterns,
etc.

* Whackamole games with the CI.

Add roundtrip test on new type and ops.

Update the python tests. Also change test to eliminate deprecation
warnings.

Add invlid IR checks for new operations.

Add sanity checks. We do not want to allow a quantum struct that holds
anything but non-owning references to qubits or qubit collections.

Remove unused folder pattern.

Workaround for overly assertive compiler warning.

Reenable the hash-and-cache of extract_ref ops in the C++ bridge. This
is a dubious optimization that we may actually want to take out at some
point, but that should be part of a distinct/different PR.

Update test to work around that pytest output can be shuffled.

Add case to python for quake.struq type.  Another python fix.

Add explicit checks to utils.py.

Stab in the dark.

---------

Signed-off-by: Alex McCaskey <[email protected]>
Co-authored-by: Alex McCaskey <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* Add multi-QPU support for the 'orca' target (#2260)

Signed-off-by: Markus Pfundstein <[email protected]>

* docstrings

Signed-off-by: Markus Pfundstein <[email protected]>

* fermioniq on correct line now. extracted hardcoded params into env vars.

Signed-off-by: Markus Pfundstein <[email protected]>

* system_clock instead of high_resolution_clock

Signed-off-by: Markus Pfundstein <[email protected]>

* removed unused code

Signed-off-by: Markus Pfundstein <[email protected]>

* removed unnecessary comment

Signed-off-by: Markus Pfundstein <[email protected]>

* fixed target description

Signed-off-by: Markus Pfundstein <[email protected]>

* removed unnecessary comments

Signed-off-by: Markus Pfundstein <[email protected]>

* Random walk phase estimation example in Python #1579 (#2060)

* Random walk phase estimation example in Python #1579

* Formatting and spelling

* Missed one formatting change

---------

Co-authored-by: Bettina Heim <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* Fixes a bug with separate compilation. (#2264)

* Fixes a bug with separate compilation.

The bridge wasn't adding all possible `__qpu__` functions to the list, so the
call converter wasn't converting a pure device kernel call on the device side.
This change fixes that bug, updates the call converter to be able to add any
missing declaration(s), and adds a regression test.

Signed-off-by: Eric Schweitz <[email protected]>

* Update the documentation.

Signed-off-by: Eric Schweitz <[email protected]>

---------

Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* added fermioniq docs

Signed-off-by: Markus Pfundstein <[email protected]>

* First draft

Signed-off-by: Markus Pfundstein <[email protected]>

* Changing CLA to use DCO (#2261)

Signed-off-by: Bettina Heim <[email protected]>

Signed-off-by: Markus Pfundstein <[email protected]>

* Fix argument passing issue in C++ bridge. (#2266)

In C++, pointers to arrays are automatically compatible with pointers
to the scalar element type. Teach the bridge this C++ rule. Add a
new regression test.

Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

* improved docs

Signed-off-by: Markus Pfundstein <[email protected]>

* added observables

Signed-off-by: Markus Pfundstein <[email protected]>

* lint

Signed-off-by: Markus Pfundstein <[email protected]>

* Log change

DCO Remediation Commit for Markus Pfundstein <[email protected]>

I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 0650288
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: deae98e
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 0ca3df0
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 5f5be12
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: e7c3338
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: d29c15b
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 5d9625c
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 25012b9
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: b7f402e
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 34b4ca1
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: b17c362
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 958de30
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 6c132ca
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 4f3a7d7
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 0d31cec
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 822dae2
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: de0ad71
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 93e9b60
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 93ba5b3
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: c293db9
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 57ccdf9
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: db1178e
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 866fac8
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: baca2db
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: c655184
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: cfc712c
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 29d79d5
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 2bb1566
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 3c8bdc9
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 25f6a2e
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 4fa3191
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 563b843
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: ebf9a72
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 2588cf5
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 9b0cf90
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 73d2b6f

Signed-off-by: Markus Pfundstein <[email protected]>

* Cleaning up docs preview for PR #5.

Signed-off-by: Markus Pfundstein <[email protected]>

* subclass from FermioniqBaseQPU instead of BaseRemoteRESTQPU

* also override the more complex launchKernel method to make sure it always invokes the correct lowerQuakeCode

* DCO Remediation Commit for Markus Pfundstein <[email protected]>

I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 20532bc
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 74d0801

Signed-off-by: Markus Pfundstein <[email protected]>

* added integration tests to CI

* DCO Remediation Commit for Markus Pfundstein <[email protected]>

I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: dc25143

Signed-off-by: Markus Pfundstein <[email protected]>

* added fermioniq to dropdown

Signed-off-by: Markus Pfundstein <[email protected]>

* reverted change to sample_result interface

* fix

* DCO Remediation Commit for Markus Pfundstein <[email protected]>

I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: 0665ac7
I, Markus Pfundstein <[email protected]>, hereby add my Signed-off-by to this commit: ac7a5c1

Signed-off-by: Markus Pfundstein <[email protected]>

* merged main

Signed-off-by: Markus Pfundstein <[email protected]>

* merged with main.

Signed-off-by: Markus Pfundstein <[email protected]>

* Update .github/workflows/config/spelling_allowlist.txt

Co-authored-by: Ben Howe <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>

---------

Signed-off-by: Markus Pfundstein <[email protected]>
Signed-off-by: Alex McCaskey <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Markus Pfundstein <[email protected]>
Co-authored-by: Anna Gringauze <[email protected]>
Co-authored-by: Pradnya Khalate <[email protected]>
Co-authored-by: Sachin Pisal <[email protected]>
Co-authored-by: Thien Nguyen <[email protected]>
Co-authored-by: Eric Schweitz <[email protected]>
Co-authored-by: Ben Howe <[email protected]>
Co-authored-by: Thien Nguyen <[email protected]>
Co-authored-by: Omar Bacarreza <[email protected]>
Co-authored-by: Pradnya Khalate <[email protected]>
Co-authored-by: Alex McCaskey <[email protected]>
Co-authored-by: Gaurang Belekar <[email protected]>
Co-authored-by: Bettina Heim <[email protected]>
Co-authored-by: Christopher Cade <[email protected]>
Co-authored-by: cuda-quantum-bot <[email protected]>
  • Loading branch information
15 people authored Oct 22, 2024
1 parent 80c0b04 commit c79671a
Show file tree
Hide file tree
Showing 24 changed files with 1,090 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/config/spelling_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ expressivity
extensibility
extremal
fermionic
fermioniq
fmt
frontend
frontends
Expand Down Expand Up @@ -235,6 +236,7 @@ namespaces
natively
normalization
nullary
observables
optimizer
optimizers
parallelization
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
- quantinuum
- nvqc
- orca
- fermioniq
single_test_name:
type: string
required: false
Expand Down Expand Up @@ -525,6 +526,56 @@ jobs:
fi
shell: bash

- name: Submit to Fermioniq test server
if: (success() || failure()) && (inputs.target == 'fermioniq' || github.event_name == 'schedule' || inputs.target == 'nightly')
run: |
echo "### Submit to Fermioniq server" >> $GITHUB_STEP_SUMMARY
export FERMIONIQ_ACCESS_TOKEN_ID='${{ secrets.FERMIONIQ_ACCESS_TOKEN_ID }}'
export FERMIONIQ_ACCESS_TOKEN_SECRET='${{ secrets.FERMIONIQ_ACCESS_TOKEN_SECRET }}'
export FERMIONIQ_PROJECT_ID='c86e2cb8-d776-41ae-8240-d3d55e18b7c3'
set +e # Allow script to keep going through errors
test_err_sum=0
cpp_tests="docs/sphinx/targets/cpp/fermioniq.cpp"
for filename in $cpp_tests; do
[ -e "$filename" ] || echo "::error::Couldn't find file ($filename)"
nvq++ \
--target fermioniq \
--fermioniq-project-id $FERMIONIQ_PROJECT_ID \
$filename
test_status=$?
if [ $test_status -eq 0 ]; then
./a.out 1> /dev/null
test_status=$?
if [ $test_status -eq 0 ]; then
echo ":white_check_mark: Successfully ran test: $filename" >> $GITHUB_STEP_SUMMARY
else
echo ":x: Test failed (failed to execute): $filename" >> $GITHUB_STEP_SUMMARY
test_err_sum=$((test_err_sum+1))
fi
else
echo ":x: Test failed (failed to compile): $filename" >> $GITHUB_STEP_SUMMARY
test_err_sum=$((test_err_sum+1))
fi
done
python_tests="docs/sphinx/targets/python/fermioniq.py docs/sphinx/targets/python/fermioniq_observables.py"
for filename in $python_tests; do
[ -e "$filename" ] || echo "::error::Couldn't find file ($filename)"
python3 $filename 1> /dev/null
test_status=$?
if [ $test_status -eq 0 ]; then
echo ":white_check_mark: Successfully ran test: $filename" >> $GITHUB_STEP_SUMMARY
else
echo ":x: Test failed (failed to execute): $filename" >> $GITHUB_STEP_SUMMARY
test_err_sum=$((test_err_sum+1))
fi
done
set -e # Re-enable exit code error checking
if [ ! $test_err_sum -eq 0 ]; then
echo "::error::${test_err_sum} tests failed. See step summary for a list of failures"
exit 1
fi
shell: bash

- name: Submit to ${{ inputs.target }}
# The full set of tests used by this step is currently only supported on
# Quantinuum. The other supported tests are tested by the step above.
Expand Down
2 changes: 2 additions & 0 deletions docs/sphinx/api/languages/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ Platform

.. doxygenclass:: cudaq::OrcaRemoteRESTQPU

.. doxygenclass:: cudaq::FermioniqBaseQPU

.. doxygenclass:: cudaq::quantum_platform
:members:

Expand Down
30 changes: 30 additions & 0 deletions docs/sphinx/targets/cpp/fermioniq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Compile and run with:
// ```
// nvq++ --target fermioniq fermioniq.cpp -o out.x && ./out.x
// ```
// This will submit the job to the fermioniq emulator.
// ```
// nvq++ --target fermioniq
// fermioniq.cpp -o out.x && ./out.x
// ```

#include <cudaq.h>
#include <fstream>

// Define a simple quantum kernel to execute on fermioniq.
struct ghz {
// Maximally entangled state between 5 qubits.
auto operator()() __qpu__ {
cudaq::qvector q(3);
h(q[0]);
for (int i = 0; i < 2; i++) {
x<cudaq::ctrl>(q[i], q[i + 1]);
}
auto result = mz(q);
}
};

int main() {
auto counts = cudaq::sample(1001, ghz());
counts.dump();
}
28 changes: 28 additions & 0 deletions docs/sphinx/targets/python/fermioniq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import cudaq
import os

remote_config = os.environ.get("FERMIONIQ_REMOTE_CONFIG_ID", "")
project_id = os.environ.get("FERMIONIQ_PROJECT_ID", "")

# You only have to set the target once! No need to redefine it
# for every execution call on your kernel.
cudaq.set_target("fermioniq", **{
"remote_config": remote_config,
"project_id": project_id
})


# Create the kernel we'd like to execute on Fermioniq.
@cudaq.kernel
def kernel():
qvector = cudaq.qvector(2)
h(qvector[0])
x.ctrl(qvector[0], qvector[1])
mz(qvector[0])
mz(qvector[1])


# Submit to Fermioniq's endpoint and confirm the program is valid.
result = cudaq.sample(kernel)

print(result)
39 changes: 39 additions & 0 deletions docs/sphinx/targets/python/fermioniq_observables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ============================================================================ #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #

import os
import cudaq
from cudaq import spin

remote_config = os.environ.get("FERMIONIQ_REMOTE_CONFIG_ID", "")
project_id = os.environ.get("FERMIONIQ_PROJECT_ID", "")

# You only have to set the target once! No need to redefine it
# for every execution call on your kernel.
cudaq.set_target("fermioniq", **{
"remote_config": remote_config,
"project_id": project_id
})


@cudaq.kernel
def kernel(theta: float):
qvector = cudaq.qvector(2)
x(qvector[0])
ry(theta, qvector[1])
x.ctrl(qvector[1], qvector[0])


spin_operator = 5.907 - 2.1433 * spin.x(0) * spin.x(1) - 2.1433 * spin.y(
0) * spin.y(1) + .21829 * spin.z(0) - 6.125 * spin.z(1)

# Pre-computed angle that minimizes the energy expectation of the `spin_operator`.
angle = 0.59

energy = cudaq.observe(kernel, spin_operator, angle).expectation()
print(f"Energy is {energy}")
1 change: 1 addition & 0 deletions docs/sphinx/using/backends/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CUDA-Q Backends
**The following is a comprehensive list of the available targets in CUDA-Q:**

* :ref:`density-matrix-cpu <default-simulator>`
* :ref:`fermioniq <fermioniq-backend>`
* :ref:`ionq <ionq-backend>`
* :ref:`anyon <anyon-backend>`
* :ref:`iqm <iqm-backend>`
Expand Down
93 changes: 92 additions & 1 deletion docs/sphinx/using/backends/simulators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,97 @@ Specific aspects of the simulation can be configured by defining the following e
The parallelism of Jacobi method (the default `CUDAQ_MPS_SVD_ALGO` setting) gives GPU better performance on small and medium size matrices.
If you expect a large number of singular values (e.g., increasing the `CUDAQ_MPS_MAX_BOND` setting), please adjust the `CUDAQ_MPS_SVD_ALGO` setting accordingly.

Fermioniq
==================================

.. _fermioniq-backend:

`Fermioniq <https://fermioniq.com/>`__ offers a cloud-based tensor-network emulation platform, `Ava <https://www.fermioniq.com/ava/>`__,
for the approximate simulation of large-scale quantum circuits beyond the memory limit of state vector and exact tensor network based methods.

The level of approximation can be controlled by setting the bond dimension: larger values yield more accurate simulations at the expense
of slower computation time. For a detailed description of Ava users are referred to the `online documentation <https://docs.fermioniq.com/>`__.

Users of CUDA-Q can access a simplified version of the full Fermioniq emulator (`Ava <https://www.fermioniq.com/ava/>`__) from either
C++ or Python. This version currently supports emulation of quantum circuits without noise, and can return measurement samples and/or
compute expectation values of observables.

.. note::
In order to use the Fermioniq emulator, users must provide access credentials. These can be requested by contacting [email protected]

The credentials must be set via two environment variables:
`FERMIONIQ_ACCESS_TOKEN_ID` and `FERMIONIQ_ACCESS_TOKEN_SECRET`.

.. tab:: Python

The target to which quantum kernels are submitted
can be controlled with the ``cudaq::set_target()`` function.

.. code:: python
cudaq.set_target('fermioniq')
You will have to specify a remote configuration id for the Fermioniq backend
during compilation.

.. code:: python
cudaq.set_target("fermioniq", **{
"remote-config": remote_config_id
})
For a comprehensive list of all remote configurations, please contact Fermioniq directly.

When your organization requires you to define a project id, you have to specify
the project id during compilation.

.. code:: python
cudaq.set_target("fermioniq", **{
"project-id": project_id
})
To specify the bond dimension, you can pass the ``fermioniq-bond-dim`` parameter.

.. code:: python
cudaq.set_target("fermioniq", **{
"bond-dim": 5
})
.. tab:: C++

To target quantum kernel code for execution in the Fermioniq backends,
pass the flag ``--target fermioniq`` to the ``nvq++`` compiler. CUDA-Q will
authenticate via the Fermioniq REST API using the environment variables
set earlier.

.. code:: bash
nvq++ --target fermioniq src.cpp ...
You will have to specify a remote configuration id for the Fermioniq backend
during compilation.

.. code:: bash
nvq++ --target fermioniq --fermioniq-remote-config <remote_config_id> src.cpp ...
For a comprehensive list of all remote configurations, please contact Fermioniq directly.

When your organization requires you to define a project id, you have to specify
the project id during compilation.

.. code:: bash
nvq++ --target fermioniq --fermioniq-project-id <project_id> src.cpp ...
To specify the bond dimension, you can pass the ``fermioniq-bond-dim`` parameter.

.. code:: bash
nvq++ --target fermioniq --fermioniq-bond-dim 10 src.cpp ...
Default Simulator
==================================

Expand Down Expand Up @@ -514,4 +605,4 @@ This will use the density matrix simulator target.

.. note::

To use targets that require an NVIDIA GPU and CUDA runtime libraries, the dependencies must be installed, else you may encounter an error stating `Invalid simulator requested`. See the section :ref:`dependencies-and-compatibility` for more information about how to install dependencies.
To use targets that require an NVIDIA GPU and CUDA runtime libraries, the dependencies must be installed, else you may encounter an error stating `Invalid simulator requested`. See the section :ref:`dependencies-and-compatibility` for more information about how to install dependencies.
13 changes: 13 additions & 0 deletions lib/Optimizer/CodeGen/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ static void addIonQPipeline(OpPassManager &pm) {
pm.addPass(createBasisConversionPass(options));
}

static void addFermioniqPipeline(OpPassManager &pm) {
using namespace cudaq::opt;
std::string basis[] = {
"h", "s", "t", "rx", "ry", "rz", "x", "y", "z", "x(1)",
};
BasisConversionPassOptions options;
options.basis = basis;
pm.addPass(createBasisConversionPass(options));
}

void cudaq::opt::registerTargetPipelines() {
PassPipelineRegistration<>("anyon-cgate-set-mapping",
"Convert kernels to Anyon gate set.",
Expand All @@ -96,6 +106,9 @@ void cudaq::opt::registerTargetPipelines() {
PassPipelineRegistration<>("ionq-gate-set-mapping",
"Convert kernels to IonQ gate set.",
addIonQPipeline);
PassPipelineRegistration<>("fermioniq-gate-set-mapping",
"Convert kernels to Fermioniq gate set.",
addFermioniqPipeline);
}

void cudaq::opt::registerCodeGenDialect(DialectRegistry &registry) {
Expand Down
1 change: 1 addition & 0 deletions python/extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ declare_mlir_python_extension(CUDAQuantumPythonSources.Extension
../runtime/cudaq/target/py_testing_utils.cpp
../runtime/mlir/py_register_dialects.cpp
../runtime/utils/PyRemoteRESTQPU.cpp
../runtime/utils/PyFermioniqRESTQPU.cpp
../runtime/utils/PyRemoteSimulatorQPU.cpp
../runtime/utils/PyRestRemoteClient.cpp
../utils/LinkedLibraryHolder.cpp
Expand Down
Loading

0 comments on commit c79671a

Please sign in to comment.