Skip to content
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

Add the CaptureMPSState() API to LT #1028

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

### Improvements

* Replace the `dummy_tensor_update` method with the `cutensornetStateCaptureMPS`API to ensure that further gates apply is allowed after the `cutensornetStateCompute` call.
[(#1028)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1028/)

* Add unit test for measurement with shots for Lightning Tensor with `tn` method.
[(#1027)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1027)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,9 @@ class MPSTNCuda final : public TNCuda<Precision, MPSTNCuda<Precision>> {
const_cast<int64_t **>(BaseType::getSitesExtentsPtr().data()),
reinterpret_cast<void **>(BaseType::getTensorsOutDataPtr().data()));

// TODO: This is a dummy tensor update to allow multiple calls to the
// `append_mps_final_state` method as well as appending additional
// operations to the graph. This is a temporary solution and this line
// can be removed in the future when the `cutensornet` backend allows
// multiple calls to the `cutensornetStateFinalizeMPS` method. For more
// details, please see the `cutensornet` high-level API workflow logic
// [here]
// (https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/api/functions.html#high-level-tensor-network-api).
// In order to proceed with the following gate operations or
// measurements after calling the `cutensornetStateCompute()` API, we
// have to call the `cutensornetStateUpdateTensor()` API, which is
// wrapped inside the `dummy_tensor_update()` method.
//
BaseType::dummy_tensor_update();
PL_CUTENSORNET_IS_SUCCESS(cutensornetStateCaptureMPS(
/* const cutensornetHandle_t */ BaseType::getTNCudaHandle(),
/* cutensornetState_t */ BaseType::getQuantumState()));
}
};
} // namespace Pennylane::LightningTensor::TNCuda
Original file line number Diff line number Diff line change
Expand Up @@ -528,30 +528,6 @@ class TNCuda : public TNCudaBase<PrecisionT, Derived> {
return sitesExtentsPtr_int64;
}

/**
* @brief Dummy tensor operator update to allow multiple calls of
* appendMPSFinalize. This is a workaround to avoid the issue of the
* cutensornet library not allowing multiple calls of appendMPSFinalize.
*
* This function either appends a new `Identity` gate to the graph when the
* gate cache is empty or update the existing gate operator by itself.
*/
void dummy_tensor_update() {
if (identiy_gate_ids_.empty()) {
applyOperation("Identity", {0}, false);
}

PL_CUTENSORNET_IS_SUCCESS(cutensornetStateUpdateTensorOperator(
/* const cutensornetHandle_t */ BaseType::getTNCudaHandle(),
/* cutensornetState_t */ BaseType::getQuantumState(),
/* int64_t tensorId*/
static_cast<int64_t>(identiy_gate_ids_.front()),
/* void* */
static_cast<void *>(
gate_cache_->get_gate_device_ptr(identiy_gate_ids_.front())),
/* int32_t unitary*/ 1));
}

/**
* @brief Save quantumState information to data provided by a user
*
Expand Down
Loading