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

Fix QubitVector::check_dimension to use only the data_size_ field #2289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gadial
Copy link
Collaborator

@gadial gadial commented Jan 16, 2025

Summary

Fixes a bug where QubitVector::check_dimension attempted to access non-existing fields.

Fixes #2284

Details and comments

Originally, QubitVector::check_dimension was defined as

template <class data_t>
void QubitVector<data_t>::check_dimension(const QubitVector &qv) const {
  if (size_ != qv.size_) {
    std::stringstream ss;
    ss << "QubitVector: vectors are different shape ";
    ss << size_ << " != " << qv.size_;
    throw std::runtime_error(ss.str());
  }
}

In 502ffcd this was changed to

template <typename data_t>
void QubitVector<data_t>::check_dimension(const QubitVector &qv) const {
  if (data_size_ != qv.size_) {
    std::string error = "QubitVector: vectors are different shape " +
                         std::to_string(data_size_) + " != " +
                         std::to_string(qv.num_states_);
    throw std::runtime_error(error);
  }
}

Along with a change of the size_ field to data_size_. It is unclear why qv.size_ remained (maybe the idea was to use qv.size()?) nor what is the meaning of qv.num_states_ (since no such field or similar getter was added). It seems to me that changing to data_size_ retains the original meaning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.16 fails to build: no member named 'size_' in 'QubitVector<data_t>'
1 participant