From 4904fa8bb3735904e18c500251f30d44f85482c9 Mon Sep 17 00:00:00 2001 From: Austin Adams Date: Sun, 30 Jun 2024 13:19:39 -0400 Subject: [PATCH] XaccQuantum: Add setter for accelerator/shots In my experience, it has been easier to treat XaccQuantum as a singleton to avoid issues with XACC initializing itself twice. It is probably cleaner to pass (accelerator, shots) via qiree::Executor, but this solves my immediate implementaiton problem in the Qwerty compiler/runtime. --- src/qirxacc/XaccQuantum.cc | 15 ++++++++++++--- src/qirxacc/XaccQuantum.hh | 7 +++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/qirxacc/XaccQuantum.cc b/src/qirxacc/XaccQuantum.cc index 7c3df24..e09e420 100644 --- a/src/qirxacc/XaccQuantum.cc +++ b/src/qirxacc/XaccQuantum.cc @@ -51,9 +51,7 @@ XaccQuantum::XaccQuantum(std::ostream& os, xacc::setIsPyApi(); // Create accelerator - accelerator_ = xacc::getAccelerator(accel_name); - QIREE_VALIDATE(accelerator_, << "failed to create accelerator"); - accelerator_->updateConfiguration({{"shots", static_cast(shots)}}); + set_accelerator_and_shots(accel_name, shots); // TODO: bit order is accelerator-dependent? endian_ = Endianness::little; @@ -76,6 +74,17 @@ XaccQuantum::~XaccQuantum() xacc::Finalize(); } +//---------------------------------------------------------------------------// +/*! + * Update the XACC accelerator and shot count. + */ +void XaccQuantum::set_accelerator_and_shots( + std::string const& accel_name, size_type shots) { + accelerator_ = xacc::getAccelerator(accel_name); + QIREE_VALIDATE(accelerator_, << "failed to create accelerator"); + accelerator_->updateConfiguration({{"shots", static_cast(shots)}}); +} + //---------------------------------------------------------------------------// /*! * Prepare to build a quantum circuit for an entry point. diff --git a/src/qirxacc/XaccQuantum.hh b/src/qirxacc/XaccQuantum.hh index 1fb793f..8e7a5db 100644 --- a/src/qirxacc/XaccQuantum.hh +++ b/src/qirxacc/XaccQuantum.hh @@ -58,6 +58,13 @@ class XaccQuantum final : virtual public QuantumNotImpl size_type num_qubits() const { return num_qubits_; } //!@} + //!@{ + //! \name Mutators + // Update the XACC accelerator and shot count + void set_accelerator_and_shots( + std::string const& accel_name, size_type shots); + //!@} + //!@{ //! \name Quantum interface // Prepare to build a quantum circuit for an entry point