Skip to content
Merged
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ set(QIREE_RUNTIME_OUTPUT_DIRECTORY
enable_language(C) # Needed for LLVM
find_package(LLVM REQUIRED)
if((LLVM_VERSION VERSION_LESS 14)
OR (LLVM_VERSION VERSION_GREATER_EQUAL 20))
message(WARNING "QIR-EE is only tested with LLVM 14-19: found version ${LLVM_VERSION}")
OR (LLVM_VERSION VERSION_GREATER_EQUAL 21))
message(WARNING "QIR-EE is only tested with LLVM 14-20: found version ${LLVM_VERSION}")
endif()

if(QIREE_USE_QSIM)
Expand Down
6 changes: 3 additions & 3 deletions app/qir-qsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//---------------------------------------------------------------------------//
//! \file qir-xacc/qir-xacc.cc
//! \file qir-qsim/qir-qsim.cc
//---------------------------------------------------------------------------//
#include <cstdlib>
#include <iostream>
Expand All @@ -13,8 +13,8 @@
#include "qiree/Executor.hh"
#include "qiree/Module.hh"
#include "qiree/ResultDistribution.hh"
#include "qirqsim/QsimDefaultRuntime.hh"
#include "qirqsim/QsimQuantum.hh"
#include "qirqsim/QsimRuntime.hh"

using namespace std::string_view_literals;

Expand All @@ -30,7 +30,7 @@ void run(std::string const& filename, int num_shots)

// Set up qsim
QsimQuantum sim(std::cout, 0);
QsimDefaultRuntime rt(std::cout, sim);
QsimRuntime rt(std::cout, sim);
ResultDistribution distribution;

// Run several time = shots (default 1)
Expand Down
1 change: 1 addition & 0 deletions src/qiree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ qiree_add_library(qiree
Module.cc
Executor.cc
ResultDistribution.cc
SingleResultRuntime.cc
QuantumNotImpl.cc
)
target_compile_features(qiree PUBLIC cxx_std_17)
Expand Down
2 changes: 1 addition & 1 deletion src/qiree/QuantumInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class QuantumInterface
virtual Result measure(Array, Array) = 0; //!< body
virtual Result mresetz(Qubit) = 0; //!< body
virtual void mz(Qubit, Result) = 0; //!< body
virtual QState read_result(Result) = 0; //!< body
virtual QState read_result(Result) const = 0; //!< body

//@}
//@{
Expand Down
2 changes: 1 addition & 1 deletion src/qiree/QuantumNotImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void QuantumNotImpl::mz(Qubit, Result)
{
QIREE_NOT_IMPLEMENTED("quantum instruction 'mz.body'");
}
QState QuantumNotImpl::read_result(Result)
QState QuantumNotImpl::read_result(Result) const
{
QIREE_NOT_IMPLEMENTED("quantum instruction 'read_result.body'");
}
Expand Down
2 changes: 1 addition & 1 deletion src/qiree/QuantumNotImpl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class QuantumNotImpl : virtual public QuantumInterface
Result measure(Array, Array) override;
Result mresetz(Qubit) override;
void mz(Qubit, Result) override;
QState read_result(Result) override;
QState read_result(Result) const override;

//@}
//@{
Expand Down
2 changes: 1 addition & 1 deletion src/qiree/RecordedResult.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RecordedResult
RecordedResult() = default;

// Construct with size and optional label
RecordedResult(std::size_t count, OptionalCString label);
inline RecordedResult(std::size_t count, OptionalCString label);

explicit RecordedResult(std::size_t count) : RecordedResult{count, nullptr}
{
Expand Down
37 changes: 37 additions & 0 deletions src/qiree/SingleResultRuntime.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//----------------------------------*-C++-*----------------------------------//
// Copyright 2025 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 qiree/SingleResultRuntime.cc
//---------------------------------------------------------------------------//
#include "SingleResultRuntime.hh"

#include "QuantumInterface.hh"

namespace qiree
{
//---------------------------------------------------------------------------//
//! Mark the following N results as being part of an array named tag
void SingleResultRuntime::array_record_output(size_type size,
OptionalCString tag)
{
result_ = RecordedResult(size, tag);
}

//! Mark the following N results as being part of a tuple named tag
void SingleResultRuntime::tuple_record_output(size_type size,
OptionalCString tag)
{
result_ = RecordedResult(size, tag);
}

//! Save one result
void SingleResultRuntime::result_record_output(Result result,
OptionalCString tag)
{
result_.push_back(sim_->read_result(result), tag);
}

//---------------------------------------------------------------------------//
} // namespace qiree
46 changes: 46 additions & 0 deletions src/qiree/SingleResultRuntime.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//----------------------------------*-C++-*----------------------------------//
// Copyright 2025 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 qiree/SingleResultRuntime.hh
//---------------------------------------------------------------------------//
#pragma once

#include "RecordedResult.hh"
#include "RuntimeInterface.hh"
#include "qiree/Assert.hh"

namespace qiree
{
class QuantumInterface;
//---------------------------------------------------------------------------//
/*!
* Interface class for recording a single shot per execution.
*/
class SingleResultRuntime : public RuntimeInterface
{
public:
// Mark the following N results as being part of an array named tag
void array_record_output(size_type size, OptionalCString tag) final;

// Mark the following N results as being part of a tuple named tag
void tuple_record_output(size_type size, OptionalCString tag) final;

// Save one result
void result_record_output(Result result, OptionalCString tag) final;

//! Access the saved results
RecordedResult const& result() const { return result_; }

protected:
// This class should only be constructed from a daughter
explicit SingleResultRuntime(QuantumInterface const& sim) : sim_{&sim} {}

private:
QuantumInterface const* sim_;
RecordedResult result_;
};

//---------------------------------------------------------------------------//
} // namespace qiree
2 changes: 1 addition & 1 deletion src/qirqsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Adding qsim as a library to qiree
qiree_add_library(qirqsim
QsimQuantum.cc
QsimDefaultRuntime.cc
QsimRuntime.cc
)

#Link the qsim library to qiree and any other relevant libraries
Expand Down
76 changes: 0 additions & 76 deletions src/qirqsim/QsimDefaultRuntime.hh

This file was deleted.

6 changes: 4 additions & 2 deletions src/qirqsim/QsimQuantum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ void QsimQuantum::mz(Qubit q, Result r)
* \todo We could add assertions to check that we actually measured into the
* given result.
*/
QState QsimQuantum::read_result(Result r)
QState QsimQuantum::read_result(Result r) const
{
return this->get_result(r);
QIREE_EXPECT(r.value < results_.size());
auto result_bool = static_cast<bool>(results_[r.value]);
return static_cast<QState>(result_bool);
}

//---------------------------------------------------------------------------//
Expand Down
15 changes: 1 addition & 14 deletions src/qirqsim/QsimQuantum.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class QsimQuantum final : virtual public QuantumNotImpl
//! Number of classical result registers
size_type num_results() const { return results_.size(); }

// Get the result from a classical register
inline QState get_result(Result r) const;
//!@}

//!@{
Expand All @@ -57,7 +55,7 @@ class QsimQuantum final : virtual public QuantumNotImpl
void mz(Qubit, Result) final;

// Read the value of a result.
QState read_result(Result) final;
QState read_result(Result) const final;
//!@}

//!@{
Expand Down Expand Up @@ -110,15 +108,4 @@ class QsimQuantum final : virtual public QuantumNotImpl
void add_gate(Ts&&... args);
};

//---------------------------------------------------------------------------//
/*!
* Get the result from a classical register.
*/
QState QsimQuantum::get_result(Result r) const
{
QIREE_EXPECT(r.value < results_.size());
auto result_bool = static_cast<bool>(results_[r.value]);
return static_cast<QState>(result_bool);
}

} // namespace qiree
16 changes: 13 additions & 3 deletions src/qirqsim/QsimDefaultRuntime.cc → src/qirqsim/QsimRuntime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//---------------------------------------------------------------------------//
//! \file qirqsim/QsimDefaultRuntime.cc
//! \file qirqsim/QsimRuntime.cc
//---------------------------------------------------------------------------//
#include "QsimDefaultRuntime.hh"
#include "QsimRuntime.hh"

#include <iostream>

#include "QsimQuantum.hh"
#include "qiree/Assert.hh"

namespace qiree
{
//---------------------------------------------------------------------------//
/*!
* Construct with quantum reference to access classical registers.
*/
QsimRuntime::QsimRuntime(std::ostream& output, QsimQuantum const& sim)
: SingleResultRuntime{sim}, output_(output)
{
}

//---------------------------------------------------------------------------//
/*!
* Initialize the execution environment, resetting qubits.
*/
void QsimDefaultRuntime::initialize(OptionalCString env)
void QsimRuntime::initialize(OptionalCString env)
{
if (env)
{
Expand Down
37 changes: 37 additions & 0 deletions src/qirqsim/QsimRuntime.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//----------------------------------*-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 qirqsim/QsimRuntime.hh
//---------------------------------------------------------------------------//
#pragma once

#include "qiree/SingleResultRuntime.hh"

namespace qiree
{
//---------------------------------------------------------------------------//
class QsimQuantum;

//---------------------------------------------------------------------------//

class QsimRuntime final : virtual public SingleResultRuntime
{
public:
// Construct with quantum reference to access classical registers
QsimRuntime(std::ostream& output, QsimQuantum const& sim);

//!@{
//! \name Runtime interface

// Initialize the execution environment, resetting qubits
void initialize(OptionalCString env) override;

//!@}

private:
std::ostream& output_;
};

} // namespace qiree
2 changes: 1 addition & 1 deletion src/qirxacc/XaccQuantum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ continue: ; preds = %else, %then
*
*
*/
QState XaccQuantum::read_result(Result r)
QState XaccQuantum::read_result(Result r) const
{
QIREE_EXPECT(r.value < this->num_results());

Expand Down
2 changes: 1 addition & 1 deletion src/qirxacc/XaccQuantum.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class XaccQuantum final : virtual public QuantumNotImpl
void mz(Qubit, Result) final;

// Read the value of a result.
QState read_result(Result) final;
QState read_result(Result) const final;
//!@}

//!@{
Expand Down
Loading