Skip to content

Commit

Permalink
Implement Var()
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed May 22, 2024
1 parent 4cb0c17 commit eb4be4b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pennylane_qrack/qrack_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice {
auto HamiltonianObservable(const std::vector<double> &coeffs, const std::vector<ObsIdType> &obs)
-> ObsIdType override
{
return 0;
return -1;
}
auto Measure(QubitIdType id, std::optional<int> postselect) -> Result override {
bool *ret = (bool *)malloc(sizeof(bool));
Expand Down Expand Up @@ -678,11 +678,16 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice {
// dev_controlled_wires, controlled_values);
// }
}
auto Expval(ObsIdType id) -> double override {
auto Expval(ObsIdType id) -> double override
{
const QrackObservable& obs = obs_cache[id];
return qsim->ExpectationPauliAll(obs.wires, obs.obs);
}
auto Var(ObsIdType) -> double override { return 0.0; }
auto Var(ObsIdType id) -> double override
{
const QrackObservable& obs = obs_cache[id];
return qsim->VariancePauliAll(obs.wires, obs.obs);
}
void State(DataView<std::complex<double>, 1>& sv) override
{
RT_FAIL_IF(sv.size() != (size_t)qsim->GetMaxQPower(), "Invalid size for the pre-allocated state vector");
Expand Down

0 comments on commit eb4be4b

Please sign in to comment.