Skip to content

Conversation

kvmto
Copy link

@kvmto kvmto commented Sep 2, 2025

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.

@@ -0,0 +1,267 @@
/*************************************************************** -*- C++ -*- ***
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/*************************************************************** -*- 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`
Copy link
Collaborator

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"> {
Copy link
Collaborator

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.

}



Copy link
Collaborator

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.



if (funcName == "save_state") {
builder.create<quake::SaveStateOp>(loc, TypeRange{}, ValueRange{});
Copy link
Collaborator

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()
Copy link
Collaborator

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.

Comment on lines 28 to 29


Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

/// 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>>;
Copy link
Collaborator

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.



static void
__quantum__qis__save_state() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
__quantum__qis__save_state() {
get_simulation_state() {

@@ -0,0 +1,43 @@
/*******************************************************************************
Copy link
Collaborator

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>
Copy link

copy-pr-bot bot commented Sep 19, 2025

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.

Signed-off-by: Kevin Mato <kmato@nvidia.com>
Signed-off-by: Kevin Mato <kmato@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants