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 required_memory_mb #1881

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
65 changes: 65 additions & 0 deletions releasenotes/notes/fix_required_memory_mb-7aeafa0fe553b85a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
hhorii marked this conversation as resolved.
Show resolved Hide resolved
prelude: >
Replace this text with content to appear at the top of the section for this
release. All of the prelude content is merged together and then rendered
separately from the items listed in other parts of the file, so the text
needs to be worded so that both the prelude and the other items make sense
when read independently. This may mean repeating some details. Not every
release note requires a prelude. Usually only notes describing major
features or adding release theme details should have a prelude.
features:
- |
List new features here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
issues:
- |
List known issues here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
upgrade:
- |
List upgrade notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
deprecations:
- |
List deprecations notes here, or remove this section. All of the list
items in this section are combined when the release notes are rendered, so
the text needs to be worded so that it does not depend on any information
only available in another section, such as the prelude. This may mean
repeating some details.
critical:
- |
Add critical notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
security:
- |
Add security notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
fixes:
- |
Add normal bug fixes here, or remove this section. All of the list items
in this section are combined when the release notes are rendered, so the
text needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
other:
- |
Add other notes here, or remove this section. All of the list items in
this section are combined when the release notes are rendered, so the text
needs to be worded so that it does not depend on any information only
available in another section, such as the prelude. This may mean repeating
some details.
1 change: 0 additions & 1 deletion src/simulators/density_matrix/densitymatrix_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ template <class densmat_t>
size_t State<densmat_t>::required_memory_mb(
uint_t num_qubits, const std::vector<Operations::Op> &ops) const {
(void)ops; // avoid unused variable compiler warning
(void)ops; // avoid unused variable compiler warning
densmat_t tmp;
return tmp.required_memory_mb(2 * num_qubits);
}
Expand Down
2 changes: 2 additions & 0 deletions src/simulators/statevector/qubitvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ size_t QubitVector<data_t>::required_memory_mb(uint_t num_qubits) const {

size_t unit = std::log2(sizeof(std::complex<data_t>));
size_t shift_mb = std::max<int_t>(0, num_qubits + unit - 20);
if (shift_mb >= 63)
return SIZE_MAX;
size_t mem_mb = 1ULL << shift_mb;
return mem_mb;
}
Expand Down
3 changes: 2 additions & 1 deletion src/simulators/statevector/qubitvector_thrust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,9 @@ size_t QubitVectorThrust<data_t>::required_memory_mb(uint_t num_qubits) const {

size_t unit = std::log2(sizeof(std::complex<data_t>));
size_t shift_mb = std::max<int_t>(0, num_qubits + unit - 20);
if (shift_mb >= 63)
return SIZE_MAX;
size_t mem_mb = 1ULL << shift_mb;

return mem_mb;
}

Expand Down
7 changes: 2 additions & 5 deletions src/simulators/unitary/unitary_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,9 @@ bool State<densmat_t>::apply_batched_op(const int_t iChunk,
template <class unitary_matrix_t>
size_t State<unitary_matrix_t>::required_memory_mb(
uint_t num_qubits, const std::vector<Operations::Op> &ops) const {
// An n-qubit unitary as 2^2n complex doubles
// where each complex double is 16 bytes
(void)ops; // avoid unused variable compiler warning
size_t shift_mb = std::max<int_t>(0, num_qubits + 4 - 20);
size_t mem_mb = 1ULL << (2 * shift_mb);
return mem_mb;
unitary_matrix_t tmp;
return tmp.required_memory_mb(2 * num_qubits);
}

template <class unitary_matrix_t>
Expand Down
Loading