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

Add constructors and mutators useful downstream #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/qiree/Module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions src/qiree/Module.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
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 @@ -57,6 +57,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