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

Merged
merged 2 commits into from
Jan 24, 2025

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.

@gadial gadial requested review from doichanj and hhorii January 20, 2025 10:57
@gadial gadial requested a review from doichanj January 23, 2025 10:26
@gadial gadial removed the request for review from hhorii January 24, 2025 04:43
@doichanj doichanj self-requested a review January 24, 2025 04:47
@gadial gadial merged commit 0bd1716 into Qiskit:main Jan 24, 2025
34 checks passed
@gadial gadial deleted the fix_check_dimension branch January 24, 2025 05:34
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>'
2 participants