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

Remove SVDynamic #999

Merged
merged 9 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* Add native N-controlled generators and adjoint support to `lightning.gpu`'s single-GPU backend.
[(#970)](https://github.com/PennyLaneAI/pennylane-lightning/pull/970)

* Add a Catalyst-specific wrapping class for Lightning Qubit.
* Add a Catalyst-specific wrapping class for Lightning-Qubit.
[(#960)](https://github.com/PennyLaneAI/pennylane-lightning/pull/960)
[(#999)](https://github.com/PennyLaneAI/pennylane-lightning/pull/999)

* Add native N-controlled gates support to `lightning.gpu`'s single-GPU backend.
[(#938)](https://github.com/PennyLaneAI/pennylane-lightning/pull/938)
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.40.0-dev11"
__version__ = "0.40.0-dev12"
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#include "Utils.hpp"

#include "ObservablesLQubit.hpp"
#include "StateVectorLQubitDynamic.hpp"
#include "StateVectorLQubitManaged.hpp"

namespace {
using Pennylane::LightningQubit::StateVectorLQubitDynamic;
using Pennylane::LightningQubit::StateVectorLQubitManaged;
using Pennylane::LightningQubit::Observables::HermitianObs;
using Pennylane::LightningQubit::Observables::NamedObs;
using Pennylane::LightningQubit::Observables::TensorProdObs;
Expand All @@ -43,7 +43,7 @@ namespace Catalyst::Runtime::Simulator {
*/
template <typename PrecisionT> class LightningObsManager {
private:
using VectorStateT = StateVectorLQubitDynamic<PrecisionT>;
using VectorStateT = StateVectorLQubitManaged<PrecisionT>;
using ComplexT = typename VectorStateT::ComplexT;
using ObservablePairType =
std::pair<std::shared_ptr<Observable<VectorStateT>>, ObsType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,29 @@
namespace Catalyst::Runtime::Simulator {

auto LightningSimulator::AllocateQubit() -> QubitIdType {
dime10 marked this conversation as resolved.
Show resolved Hide resolved
size_t sv_id = this->device_sv->allocateWire();
return this->qubit_manager.Allocate(sv_id);
const std::size_t num_qubits = this->device_sv->getNumQubits();

if (num_qubits == 0U) {
this->device_sv = std::make_unique<StateVectorT>(1);
return this->qubit_manager.Allocate(num_qubits);
}

std::vector<std::complex<double>, AlignedAllocator<std::complex<double>>>
data = this->device_sv->getDataVector();
const std::size_t dsize = data.size();
data.resize(dsize << 1UL);

auto src = data.begin();
std::advance(src, dsize - 1);

for (auto dst = data.end() - 2; src != data.begin();
std::advance(src, -1), std::advance(dst, -2)) {
*dst = *src;
*src = std::complex<double>(.0, .0);
}

this->device_sv = std::make_unique<StateVectorT>(data);
return this->qubit_manager.Allocate(num_qubits);
}

auto LightningSimulator::AllocateQubits(size_t num_qubits)
Expand All @@ -45,14 +66,11 @@ auto LightningSimulator::AllocateQubits(size_t num_qubits)
}

void LightningSimulator::ReleaseAllQubits() {
this->device_sv->clearData();
this->qubit_manager.ReleaseAll();
this->device_sv = std::make_unique<StateVectorT>(0); // reset the device
}

void LightningSimulator::ReleaseQubit(QubitIdType q) {
if (this->qubit_manager.isValidQubitId(q)) {
this->device_sv->releaseWire(this->qubit_manager.getDeviceId(q));
}
dime10 marked this conversation as resolved.
Show resolved Hide resolved
this->qubit_manager.Release(q);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <numeric>
#include <span>

#include "StateVectorLQubitDynamic.hpp"
#include "StateVectorLQubitManaged.hpp"

#include "CacheManager.hpp"
#include "Exception.hpp"
Expand All @@ -35,7 +35,7 @@ namespace Catalyst::Runtime::Simulator {
class LightningSimulator final : public Catalyst::Runtime::QuantumDevice {
private:
using StateVectorT =
Pennylane::LightningQubit::StateVectorLQubitDynamic<double>;
Pennylane::LightningQubit::StateVectorLQubitManaged<double>;

// static constants for RESULT values
static constexpr bool GLOBAL_RESULT_TRUE_CONST = true;
Expand Down

This file was deleted.

Loading
Loading