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.

@copy-pr-bot
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.

- added erase pass
- fixed bug on platforms

- serialization and deserialization of simulation state
- training mode, for error log collection and further propagation
- semplifications

Signed-off-by: Kevin Mato <[email protected]>
Signed-off-by: Kevin Mato <[email protected]>
@kvmto kvmto changed the title DRAFT: cudaq::save_state, and simulation support cudaq::save_state, and error propagation Oct 21, 2025
Signed-off-by: Kevin Mato <[email protected]>
@kvmto
Copy link
Author

kvmto commented Oct 21, 2025

/ok to test 6c05744

Command Bot: Processing...

kvmto added 14 commits October 21, 2025 13:27
Signed-off-by: Kevin Mato <[email protected]>
Signed-off-by: Kevin Mato <[email protected]>
- added erase pass
- fixed bug on platforms

- serialization and deserialization of simulation state
- training mode, for error log collection and further propagation
- semplifications

Signed-off-by: Kevin Mato <[email protected]>
Signed-off-by: Kevin Mato <[email protected]>
Signed-off-by: Kevin Mato <[email protected]>
Signed-off-by: Kevin Mato <[email protected]>
Signed-off-by: Kevin Mato <[email protected]>
@bmhowe23
Copy link
Collaborator

bmhowe23 commented Oct 21, 2025

/ok to test 6c05744

Command Bot: Processing...

@copy-pr-bot
Copy link

copy-pr-bot bot commented Oct 21, 2025

/ok to test 6c05744

@bmhowe23, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@bmhowe23
Copy link
Collaborator

bmhowe23 commented Oct 21, 2025

/ok to test 727a9fb

Command Bot: Processing...

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.

3 participants