Open kalzoo opened 2 years ago
The trickier thing is going to be figuring out the C API for this. Do we need a function call for accessing each slot of data (e.g. get_data(result.handle, "ro", 7)
)? I feel like that would add significant overhead in the run -> get results -> tweak params -> run loops.
We could allocate the whole array and just fill in 0s for any values we didn't get? What does pyQuil
do?
We could allocate the whole array and just fill in 0s for any values we didn't get? What does pyQuil do?
Yes, I believe that's what we should do, to present the facade of initialized-but-not-written memory being returned from execution. It appears that pyQuil allocates but does not initialize a new array, which I'd describe as an oversight and likely a bug.
Currently, in
qcs/src/qpu/mod.rs
,organize_ro_sources
, there's a block which enforces that readout targets contiguous memory regions starting from0
, that is, this program is invalid because it skipsro[0..6]
:However, this is both valid Quil and accepted by
pyQuil
and the QCS API. When executed bypyQuil
, hero_sources
returned look like this:and the execution result looks like this (note the uninitialized memory in indices 0..6:
The assertion that this Rust SDK is making makes sense in terms of being able to iterate safely through the result, esp via C, but it cannot add constraints to the Quil language in order to do so. We could consider a map (probably a
BTreeMap
to preserve ordering for iteration) or a sparse Vec (maybe aVec<Option<_>>
) to store these sparse results.