qsharp-runtime icon indicating copy to clipboard operation
qsharp-runtime copied to clipboard

Make the Native Simulator API More Reusable and Reuse it in Runtime

Open kuzminrobin opened this issue 3 years ago • 0 comments

The Native Simulator has the Dump call with the following declaration:

MICROSOFT_QUANTUM_DECL void Dump(_In_ unsigned sid, _In_ bool (*callback)(size_t, double, double));

Its second parameter's type is defined in-place, which prevents its reuse in the calling code in Runtime. The calling code has to re-define that type:

typedef bool (*TGetStateCallback)(size_t /*basis vector*/, double /* amplitude Re*/, double /* amplitude Im*/);

Also the Native Simulator is compiled into the dynamic library that exposes its API in the header capi.hpp, but the Runtime does not include that header. That is why the calling code in the Runtime re-declares all the Native Simulator's API function signatures, e.g. the Dump() call signature is re-declared like this:

typedef bool (*TDump)(unsigned, TGetStateCallback);

(pay attention to the return type bool as opposed to the actual return type void in the first-most listing above). To avoid re-declaration, start including the capi.hpp in the Runtime.

See also #631.

kuzminrobin avatar Mar 29 '21 18:03 kuzminrobin