-
Notifications
You must be signed in to change notification settings - Fork 197
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
[RFC] [Language] Quantum allocation with state initialization #1086
Comments
Thanks @amccaskey for proposing this. I have a clarification question regarding the semantics of a __qpu__ bool foo() {
// Init from state vector
cudaq::qvector q = {0., 1., 0., 0.};
return cudaq::mz(q[0]);
} I see two possibilities:
Thinking a bit forward, it seems to me that the second option is more appropriate. Eventually, we can define a quantum integer type, say __qpu__ bool foo() {
// Init from state vector
cudaq::qint q = {0., 1., 0., 0.};
return cudaq::mz(q[0]);
} In this case, the kernel must return |
To make the API future-proof, we could also consider adding an optional bit-ordering vector argument (similar to
The default when none provided could be one of those two endian conventions, e.g., LSB. |
@boschmitt I prefer we go with bullet 2. |
@boschmitt for your |
One thing to add, it will likely be good to update the __qpu__ void test4(const cudaq::state &state) {
// Input state could wrap GPU device pointer
cudaq::qvector q = state;
... build off initial state ...
}
void useTest4() {
auto initStateGen = [](...) __qpu__ { ... };
auto intState = cudaq::get_state(initStateGen, ...);
cudaq::sample(test4, initState).dump();
} |
Would this be interpreted as the bitstring If the goal is to construct states restricted to the computational basis, I would think rather than |
We can certainly support it, but we would still have to define what it means with respect to a state vector. There will be more question to answer in order to support this idea. For example:
Let me try to rephrase my questions: If we have a set of qubits we can try to initialize this set using a state vector, then the we need clarity on:
|
I guess |
I agree. The main point for which I asked clarification is with regards of how the semantics of the state vector relates to the type, |
See PR #1461 |
@schweitzpgi I think we can probably start thinking about MLIR support and QIR lowering for a __qpu__ void kernel(cudaq::state inState) {
cudaq::qvector q = inState;
...
} in anticipation of #1467. I think we can just treat this like Clang would and lower to a |
Some notes about the ownership semantics for
(1) Adopting reference semantics
(2) Adopting move semantics
|
Building on Thien's comment above on move semantics, the For performance reasons, let the user decide what happens to the Move semanticsThis seems straightforward. The cudaq::state state = ...;
qvector q(std::move(state));
// the variable `state` is dead/invalid at this point In this case, this code can be optimized a bit since Reference copy semanticsIf the cudaq::state state = ...;
qvector q1(state); // calls qvector(cudaq::state);
// the variable `state` still has a reference to the state information
...
// the `state` information, while it can clearly be referenced may have _changed_ in the code above
qvector q2(state); // Surprise? q2 does not have the same initial state as q1! |
In the updated code, we'd add the full set of
In particular, the In the above example, adding
|
Would we like to support the following python cases? # Passing np arrays as params
c = np.array(c, dtype=cudaq.complex())
@cudaq.kernel
def kernel(vec: np.array):
q = cudaq.qvector(vec)
c = np.array(c, dtype=cudaq.complex())
@cudaq.kernel
def kernel(vec: np.ndarray):
q = cudaq.qvector(vec)
c = np.array(c, dtype=cudaq.complex())
@cudaq.kernel
def kernel(vec: np.ndarray[any, complex]):
q = cudaq.qvector(vec) |
Closing this - any remaining work is tracked separately. |
TODO:
CircuitSimulator::addQubitsToState(with data)
), need kron-prod on GPU (@anthony-santana)vector<complex>
kernel input works end-to-end (@anthony-santana)from_state
decomposition in MLIR (@annagrin)Example with #1467
kernel(cudaq::state& initState) { cudaq::qvector q = initState; }
I propose we update the language to support quantum allocation with user-provided initial state specification. This should supersede functions like
from_state(...)
on thekernel_builder
.C++:
New constructors
New builder method
Python
The Python builder would be similar as in the following.
C++ Usage
The following snippet demonstrates what this might look like:
Python usage
Vectors of complex or floating-point numbers
Notes
qvector
initializer does not match the current simulation precisioncudaq.amplitudes
orcudaq.complex
.Lists
Numpy arrays
cudaq.State
For library-mode / simulation we pass the state data along to NVQIR. For physical backends, we can replace runtime state data with the result of a circuit synthesis pass (like the current implementation in
from_state(...)
.The text was updated successfully, but these errors were encountered: