Skip to content

Commit 9f3cf06

Browse files
Add the CaptureMPSState() API to LT (#1028)
### Before submitting Please complete the following checklist when submitting a PR: - [ ] All new features must include a unit test. If you've fixed a bug or added code that should be tested, add a test to the [`tests`](../tests) directory! - [ ] All new functions and code must be clearly commented and documented. If you do make documentation changes, make sure that the docs build and render correctly by running `make docs`. - [ ] Ensure that the test suite passes, by running `make test`. - [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing the change, and including a link back to the PR. - [x] Ensure that code is properly formatted by running `make format`. When all the above are checked, delete everything above the dashed line and fill in the pull request template. ------------------------------------------------------------------------------------------------------------ **Context:** [SC-80074] Replace the `dummy_tensor_update` method with the `cutensornetStateCaptureMPS`API released `cutensornet-v24.11` to ensure that further gates apply is allowed after the `cutensornetStateCompute` call. **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent 42d3b8e commit 9f3cf06

File tree

4 files changed

+7
-39
lines changed

4 files changed

+7
-39
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
### Improvements
3131

32+
* Replace the `dummy_tensor_update` method with the `cutensornetStateCaptureMPS`API to ensure that further gates apply is allowed after the `cutensornetStateCompute` call.
33+
[(#1028)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1028/)
34+
3235
* Add unit test for measurement with shots for Lightning Tensor with `tn` method.
3336
[(#1027)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1027)
3437

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.40.0-dev39"
19+
__version__ = "0.40.0-dev40"

pennylane_lightning/core/src/simulators/lightning_tensor/tncuda/MPSTNCuda.hpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,9 @@ class MPSTNCuda final : public TNCuda<Precision, MPSTNCuda<Precision>> {
238238
const_cast<int64_t **>(BaseType::getSitesExtentsPtr().data()),
239239
reinterpret_cast<void **>(BaseType::getTensorsOutDataPtr().data()));
240240

241-
// TODO: This is a dummy tensor update to allow multiple calls to the
242-
// `append_mps_final_state` method as well as appending additional
243-
// operations to the graph. This is a temporary solution and this line
244-
// can be removed in the future when the `cutensornet` backend allows
245-
// multiple calls to the `cutensornetStateFinalizeMPS` method. For more
246-
// details, please see the `cutensornet` high-level API workflow logic
247-
// [here]
248-
// (https://docs.nvidia.com/cuda/cuquantum/latest/cutensornet/api/functions.html#high-level-tensor-network-api).
249-
// In order to proceed with the following gate operations or
250-
// measurements after calling the `cutensornetStateCompute()` API, we
251-
// have to call the `cutensornetStateUpdateTensor()` API, which is
252-
// wrapped inside the `dummy_tensor_update()` method.
253-
//
254-
BaseType::dummy_tensor_update();
241+
PL_CUTENSORNET_IS_SUCCESS(cutensornetStateCaptureMPS(
242+
/* const cutensornetHandle_t */ BaseType::getTNCudaHandle(),
243+
/* cutensornetState_t */ BaseType::getQuantumState()));
255244
}
256245
};
257246
} // namespace Pennylane::LightningTensor::TNCuda

pennylane_lightning/core/src/simulators/lightning_tensor/tncuda/TNCuda.hpp

-24
Original file line numberDiff line numberDiff line change
@@ -528,30 +528,6 @@ class TNCuda : public TNCudaBase<PrecisionT, Derived> {
528528
return sitesExtentsPtr_int64;
529529
}
530530

531-
/**
532-
* @brief Dummy tensor operator update to allow multiple calls of
533-
* appendMPSFinalize. This is a workaround to avoid the issue of the
534-
* cutensornet library not allowing multiple calls of appendMPSFinalize.
535-
*
536-
* This function either appends a new `Identity` gate to the graph when the
537-
* gate cache is empty or update the existing gate operator by itself.
538-
*/
539-
void dummy_tensor_update() {
540-
if (identiy_gate_ids_.empty()) {
541-
applyOperation("Identity", {0}, false);
542-
}
543-
544-
PL_CUTENSORNET_IS_SUCCESS(cutensornetStateUpdateTensorOperator(
545-
/* const cutensornetHandle_t */ BaseType::getTNCudaHandle(),
546-
/* cutensornetState_t */ BaseType::getQuantumState(),
547-
/* int64_t tensorId*/
548-
static_cast<int64_t>(identiy_gate_ids_.front()),
549-
/* void* */
550-
static_cast<void *>(
551-
gate_cache_->get_gate_device_ptr(identiy_gate_ids_.front())),
552-
/* int32_t unitary*/ 1));
553-
}
554-
555531
/**
556532
* @brief Save quantumState information to data provided by a user
557533
*

0 commit comments

Comments
 (0)