[C++] Type distinction for measurement result#3800
[C++] Type distinction for measurement result#3800khalatepradnya wants to merge 49 commits intoNVIDIA:mainfrom
Conversation
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
a652094 to
c6c8f57
Compare
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
44f2dab to
55e008e
Compare
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
55e008e to
3c6821a
Compare
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
790cba0 to
050825e
Compare
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
4af9350 to
c402e3e
Compare
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
5be53bc to
45b8c68
Compare
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
in `qis` directory, remove the macro for library mode and drop the typedef to bool. * Retain variable names assigned to measurement results * Disallow measure_result as argument to entry-point kernels * Drop the intrinsic funciton fro converting to Boolean vector * Insert discriminate op wherever necessary * Adjust tests * WIP Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
frontend * Add support for RESULT type in the log parser - construct a `measure_result` object. * Two tests are not working with `auto` - should be fixed * Clean-up * Handle the size for `measure_result` since it behaves differently on host and on device * Log result output Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
45b8c68 to
eecfd7f
Compare
atgeller
left a comment
There was a problem hiding this comment.
LGTM, thanks @khalatepradnya! Left a comment.
* Update expand measurement pass to handle more than one discriminate op Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
ops Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
| // The source is a pointer to measure_result (!cc.ptr<!quake.measure>) | ||
| // Just load and return the value |
There was a problem hiding this comment.
This comment specifies something invalid.
In the IR, we cannot have pointers to abstract quake types. We cannot load the abstraction and we cannot store it. (Think of a measurement type as some volatile stream of random data of infinite size. There is no way to allocate a finite amount of space for it, and even if you could, as soon as you tried to load or store it, the data would change and be something else.)
| using ComputePtrOpPattern = OpInterfacePattern<cudaq::cc::ComputePtrOp>; | ||
| using StdvecInitOpPattern = OpInterfacePattern<cudaq::cc::StdvecInitOp>; | ||
| using StdvecDataOpPattern = OpInterfacePattern<cudaq::cc::StdvecDataOp>; |
There was a problem hiding this comment.
I think we're using the wrong idiom here in retrospect. A normal stdvec<T> value is a memory buffer, but a stdvec<measure> never was. It was always expanded and converted to stdvec<bool> immediately.
Again, loading and storing quake.anytype from a stack location makes no sense.
| } | ||
| }; | ||
|
|
||
| struct LogOutputOpPattern : public OpConversionPattern<cudaq::cc::LogOutputOp> { |
There was a problem hiding this comment.
Can't this one be another OpInterfacePattern instance?
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
…ureResult` functionality. Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
`isMeasureResultSequenceType` into single function. Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
- assert on argument passed to `to_bool_vector` - revisit load / pointer logic after changes to `MeasurementsType` Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
- simply constructor - remove redundant code Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
This PR introduces comprehensive support for the
measure_resulttype throughout the CUDA-Q C++ frontend, enabling deferred discrimination of measurement results.cudaq::measure_resultclass withstd::int64_t valueandstd::int64_t unique_idfields (16 bytes).measure_resultin their signature are classified as device-only.quake.discriminateis inserted only at points where a classical value is needed: if/ternary conditions, bool/int/double casts, comparisons, arithmetic, explicitto_bool_vector()/to_integer()calls and return from entry-point kernels.These changes collectively ensure that quantum measurement results are treated as first-class citizens in the type system and IR lowering.
Breaking Changes
auto kernel() { return mz(q); }now returnsmeasure_result, making the kernel device-only.std::vector<bool> v = mz(qubits)no longer compiles; usecudaq::to_bool_vector(mz(qubits)).int x = mz(q)requiresstatic_cast<int>(mz(q)).measure_resultorstd::vector<measure_result>.Note: Python front-end changes will be covered in a separate PR.