-
Notifications
You must be signed in to change notification settings - Fork 290
DRAFT: cudaq::save_state, and simulation support #3408
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
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,267 @@ | |||
/*************************************************************** -*- C++ -*- *** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/*************************************************************** -*- C++ -*- *** | |
/****************************************************************-*- C++ -*-**** |
nit: consistency
"__quantum__rt__array_record_output"; | ||
|
||
/// Used to specify the type of the data elements in the `QISApplyKrausChannel` | ||
/// Used to specify the type of the datxa elements in the `QISApplyKrausChannel` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo?
}]; | ||
} | ||
|
||
def quake_SaveStateOp : QuakeOp<"save_state"> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there are any optimizations planned for this and therefore it shouldn't be added to the IR. It should suffice to lower this directly to a CallOp to a runtime library function that is a common decl across all simulators.
lib/Frontend/nvqpp/ConvertExpr.cpp
Outdated
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: clang-format? Shouldn't have 3 blank lines here.
lib/Frontend/nvqpp/ConvertExpr.cpp
Outdated
|
||
|
||
if (funcName == "save_state") { | ||
builder.create<quake::SaveStateOp>(loc, TypeRange{}, ValueRange{}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just generate a func::CallOp.
func.func private @__quantum__qis__convert_array_to_stdvector(!qir_array) -> !qir_array | ||
func.func private @__quantum__qis__free_converted_stdvector(!qir_array) | ||
func.func private @__quantum__qis__save_state() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really require QIR in the loop? It is only available in simulation, no? It would be clearer, if it is not a QIS function, that it will never be a part of a hardware profile and, as a bonus, the QIR verifier will fail to let it slip past as something valid for hardware.
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime/common/SimulationState.h
Outdated
/// 3: x_output array, size = x_output_size (X stabilizers + destabilisers + phase bits) | ||
/// 4: z_output array, size = z_output_size (Z stabilizers + destabilisers + phase bits) | ||
/// 5: frame array (Pauli frame), size = 2*num_qubits | ||
using StimData = std::vector<std::pair<void*, std::size_t>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above description is convoluted enough to merit making this a class
instead of a vector
with special conventions.
runtime/nvqir/NVQIR.cpp
Outdated
|
||
|
||
static void | ||
__quantum__qis__save_state() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__quantum__qis__save_state() { | |
get_simulation_state() { |
@@ -0,0 +1,43 @@ | |||
/******************************************************************************* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how you got this to compile without adding this pass to the Passes.td file.
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
bfd9c68
to
b873525
Compare
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Summary
This PR introduces cudaq::save_state along with the necessary infrastructure changes to ExecutionContext and simulators.
Motivation
The new functionality provides a way to debug the execution of kernels and to collect data from their runs. These improvements are also foundational to supporting upcoming AI projects.