-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create separate runtime for per-tuple measurements
- Loading branch information
Showing
8 changed files
with
454 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other QIR-EE developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
//---------------------------------------------------------------------------// | ||
//! \file qirxacc/XaccDefaultRuntime.cc | ||
//---------------------------------------------------------------------------// | ||
#include "XaccDefaultRuntime.hh" | ||
|
||
#include "qiree/Assert.hh" | ||
|
||
namespace qiree | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Initialize the execution environment, resetting qubits. | ||
*/ | ||
void XaccDefaultRuntime::initialize(OptionalCString env) | ||
{ | ||
if (env) | ||
{ | ||
output_ << "Argument to initialize: " << env << std::endl; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Execute circuit and mark the following N results as being part of an array | ||
* named tag | ||
*/ | ||
void XaccDefaultRuntime::array_record_output(size_type s, OptionalCString tag) | ||
{ | ||
this->execute_if_needed(); | ||
output_ << "array " << (tag ? tag : "<null>") << " length " << s | ||
<< std::endl; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Execute circuit and mark the following N results as being part of a tuple | ||
* named tag. | ||
*/ | ||
void XaccDefaultRuntime::tuple_record_output(size_type s, OptionalCString tag) | ||
{ | ||
this->execute_if_needed(); | ||
output_ << "tuple " << (tag ? tag : "<null>") << " length " << s | ||
<< std::endl; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Execute circuit and report a single measurement result | ||
*/ | ||
void XaccDefaultRuntime::result_record_output(Result r, OptionalCString tag) | ||
{ | ||
this->execute_if_needed(); | ||
Qubit q = xacc_.result_to_qubit(r); | ||
|
||
// Get a map of string ("0" and "1" ???) -> int | ||
auto counts = xacc_.get_marginal_counts({q}); | ||
|
||
// Print the result | ||
output_ << "qubit " << q.value << " experiment " << (tag ? tag : "<null>") | ||
<< ": {0: " << counts["0"] << ", 1: " << counts["1"] << '}' | ||
<< std::endl; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
// PRIVATE FUNCTIONS | ||
//---------------------------------------------------------------------------// | ||
|
||
void XaccDefaultRuntime::execute_if_needed() | ||
{ | ||
if (xacc_.execute_if_needed() && print_accelbuf_) | ||
{ | ||
xacc_.print_accelbuf(); | ||
} | ||
} | ||
} // namespace qiree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other QIR-EE developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
//---------------------------------------------------------------------------// | ||
//! \file qirxacc/XaccDefaultRuntime.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "qiree/RuntimeInterface.hh" | ||
#include "qirxacc/XaccQuantum.hh" | ||
|
||
namespace qiree | ||
{ | ||
class XaccQuantum; | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Print per-qubit measurement statistics. | ||
* | ||
* (Compare with \ref XaccTupleRuntime.) | ||
* | ||
* Example: | ||
* \code | ||
* tuple ret length 2 | ||
* qubit 0 experiment <null>: {0: 509, 1: 515} | ||
* qubit 1 experiment <null>: {0: 509, 1: 515} | ||
* \endcode | ||
*/ | ||
class XaccDefaultRuntime final : virtual public RuntimeInterface | ||
{ | ||
public: | ||
// Construct with XACC quantum runtime and options | ||
inline XaccDefaultRuntime(std::ostream& output, | ||
XaccQuantum& xacc, | ||
bool print_accelbuf); | ||
|
||
//!@{ | ||
//! \name Runtime interface | ||
// Initialize the execution environment, resetting qubits | ||
void initialize(OptionalCString env) override; | ||
|
||
//! Mark the following N results as being part of an array named tag | ||
void array_record_output(size_type, OptionalCString tag) final; | ||
|
||
//! Mark the following N results as being part of a tuple named tag | ||
void tuple_record_output(size_type, OptionalCString) final; | ||
|
||
// Save one result | ||
void result_record_output(Result result, OptionalCString tag) final; | ||
//!@} | ||
|
||
private: | ||
std::ostream& output_; | ||
XaccQuantum& xacc_; | ||
bool const print_accelbuf_; | ||
|
||
void execute_if_needed(); | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Construct an \c XaccDefaultRuntime. | ||
* | ||
* The \c print_accelbuf argument determines whether the XACC \c | ||
* AcceleratorBuffer is dumped after execution. | ||
*/ | ||
XaccDefaultRuntime::XaccDefaultRuntime(std::ostream& output, | ||
XaccQuantum& xacc, | ||
bool print_accelbuf = true) | ||
: output_(output), xacc_(xacc), print_accelbuf_(print_accelbuf) | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace qiree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.