Skip to content

Commit

Permalink
XaccQuantum: Add setter for accelerator/shots
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ausbin committed Jul 16, 2024
1 parent 610cd8a commit 67a1139
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/qirxacc/XaccQuantum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(shots)}});
set_accelerator_and_shots(accel_name, shots);
// TODO: bit order is accelerator-dependent?
endian_ = Endianness::little;

Expand All @@ -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<int>(shots)}});
}

//---------------------------------------------------------------------------//
/*!
* Prepare to build a quantum circuit for an entry point.
Expand Down
7 changes: 7 additions & 0 deletions src/qirxacc/XaccQuantum.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67a1139

Please sign in to comment.