Program Listing for File qubit_info.hpp¶
↰ Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/qulacs-rtd/checkouts/v0.6.9/src/cppsim/qubit_info.hpp
)
#pragma once
#include "type.hpp"
#define FLAG_X_COMMUTE ((UINT)(0x01))
#define FLAG_Y_COMMUTE ((UINT)(0x02))
#define FLAG_Z_COMMUTE ((UINT)(0x04))
const UINT invalid_qubit = 9999;
class DllExport QubitInfo {
protected:
UINT _index;
public:
virtual ~QubitInfo() {}
UINT index() const { return _index; }
// jupiroが勝手に作成
void set_index(int idx) { _index = idx; }
explicit QubitInfo(UINT index_) : _index(index_){};
};
class TargetQubitInfo;
class ControlQubitInfo;
class DllExport ControlQubitInfo : public QubitInfo {
private:
// \~japanese-en
// コントロール値 量子ビットの添字がコントロール値のときのみゲートが作用する
UINT _control_value;
public:
UINT control_value() const { return _control_value; }
ControlQubitInfo(void) : QubitInfo(invalid_qubit), _control_value(1){};
explicit ControlQubitInfo(UINT index_)
: QubitInfo(index_), _control_value(1){};
ControlQubitInfo(UINT index_, UINT control_value_)
: QubitInfo(index_), _control_value(control_value_){};
virtual bool is_commute_with(const TargetQubitInfo& info) const;
virtual bool is_commute_with(const ControlQubitInfo& info) const;
};
class DllExport TargetQubitInfo : public QubitInfo {
private:
// \~japanese-en この量子ビットがパウリ演算子と可換かどうかを保持する値
UINT _commutation_property;
public:
TargetQubitInfo(void)
: QubitInfo(invalid_qubit), _commutation_property(0){};
explicit TargetQubitInfo(UINT index_)
: QubitInfo(index_), _commutation_property(0){};
TargetQubitInfo(UINT index_, UINT commutation_property_)
: QubitInfo(index_), _commutation_property(commutation_property_){};
bool is_commute_X() const {
return (_commutation_property & FLAG_X_COMMUTE) != 0;
}
bool is_commute_Y() const {
return (_commutation_property & FLAG_Y_COMMUTE) != 0;
}
bool is_commute_Z() const {
return (_commutation_property & FLAG_Z_COMMUTE) != 0;
}
virtual bool is_commute_with(const TargetQubitInfo& info) const;
virtual bool is_commute_with(const ControlQubitInfo& info) const;
virtual UINT get_merged_property(UINT property) const {
return _commutation_property & property;
}
virtual UINT get_merged_property(const TargetQubitInfo& target) const {
return _commutation_property & target._commutation_property;
}
virtual UINT get_merged_property(const ControlQubitInfo& control) const {
(void)control;
return _commutation_property & FLAG_Z_COMMUTE;
}
};