From 610cd8acdd18dd590c452a6846388d210371fdc8 Mon Sep 17 00:00:00 2001 From: Austin Adams Date: Sun, 30 Jun 2024 13:17:59 -0400 Subject: [PATCH 1/2] Add constructor for llvm::Module + entrypoint name This is useful when a user generates an llvm::Module that may have multiple entry points, as the Qwerty compiler/runtime does. --- src/qiree/Module.cc | 16 ++++++++++++++++ src/qiree/Module.hh | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/qiree/Module.cc b/src/qiree/Module.cc index 346e311..83d9703 100644 --- a/src/qiree/Module.cc +++ b/src/qiree/Module.cc @@ -113,6 +113,22 @@ Module::Module(UPModule&& module) : module_{std::move(module)} << module_->getSourceFileName() << "'"); } +//---------------------------------------------------------------------------// +/*! + * Construct with an LLVM module and an entry point. + */ +Module::Module(UPModule&& module, std::string const& entrypoint) + : module_{std::move(module)} +{ + QIREE_EXPECT(module_); + + // Search for explicitly named entry point + entrypoint_ = module_->getFunction(entrypoint); + QIREE_VALIDATE(entrypoint_, + << "no entrypoint function '" << entrypoint << "' exists"); +} + + //---------------------------------------------------------------------------// /*! * Construct with an LLVM IR file (bitcode or disassembled). diff --git a/src/qiree/Module.hh b/src/qiree/Module.hh index c6ceaed..fc7247c 100644 --- a/src/qiree/Module.hh +++ b/src/qiree/Module.hh @@ -45,6 +45,9 @@ class Module // Construct from an externally created LLVM module explicit Module(UPModule&& module); + // Construct from an externally created LLVM module and an entry point + explicit Module(UPModule&& module, std::string const& entrypoint); + // Construct with an LLVM IR file (bitcode or disassembled) explicit Module(std::string const& filename); From 67a113980f8ad71972b80f637ffb851b5055c4da Mon Sep 17 00:00:00 2001 From: Austin Adams Date: Sun, 30 Jun 2024 13:19:39 -0400 Subject: [PATCH 2/2] 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 0c5be59..5f97d5e 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 3e67cfd..29e143d 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