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

[Emu-SV] tutorial emu-sv and correlation mat performance #24

Merged
merged 3 commits into from
Jan 24, 2025
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
17 changes: 8 additions & 9 deletions emu_sv/custom_callback_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ def correlation_matrix_sv_impl(
num_qubits = int(math.log2(len(state.vector)))
state_tensor = state.vector.reshape((2,) * num_qubits)

correlation_matrix = []
correlation_matrix = [[0.0] * num_qubits for _ in range(num_qubits)]

for numi in range(num_qubits):
one_correlation = []
select_i = state_tensor.select(numi, 1)
for numj in range(num_qubits):
if numj < numi:
one_correlation.append((select_i.select(numj, 1).norm() ** 2).item())
elif numj > numi: # the selected atom is deleted
one_correlation.append((select_i.select(numj - 1, 1).norm() ** 2).item())
for numj in range(numi, num_qubits): # select the upper triangle
if numi == numj:
value = (select_i.norm() ** 2).item()
else:
one_correlation.append((select_i.norm() ** 2).item())
value = (select_i.select(numj - 1, 1).norm() ** 2).item()

correlation_matrix.append(one_correlation)
correlation_matrix[numi][numj] = value
correlation_matrix[numj][numi] = value
return correlation_matrix


Expand Down
12 changes: 8 additions & 4 deletions emu_sv/sv_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ def __init__(
for num, obs in enumerate(self.callbacks): # monkey patch
obs_copy = copy.deepcopy(obs)
if isinstance(obs, QubitDensity):
obs_copy.apply = MethodType(qubit_density_sv_impl, obs) # type: ignore[method-assign]
# type: ignore[method-assign]
obs_copy.apply = MethodType(qubit_density_sv_impl, obs)
self.callbacks[num] = obs_copy
elif isinstance(obs, EnergyVariance):
obs_copy.apply = MethodType(energy_variance_sv_impl, obs) # type: ignore[method-assign]
# type: ignore[method-assign]
obs_copy.apply = MethodType(energy_variance_sv_impl, obs)
self.callbacks[num] = obs_copy
elif isinstance(obs, SecondMomentOfEnergy):
obs_copy.apply = MethodType(second_momentum_sv_impl, obs) # type: ignore[method-assign]
# type: ignore[method-assign]
obs_copy.apply = MethodType(second_momentum_sv_impl, obs)
self.callbacks[num] = obs_copy
elif isinstance(obs, CorrelationMatrix):
obs_copy.apply = MethodType(correlation_matrix_sv_impl, obs) # type: ignore[method-assign]
# type: ignore[method-assign]
obs_copy.apply = MethodType(correlation_matrix_sv_impl, obs)
self.callbacks[num] = obs_copy
665 changes: 665 additions & 0 deletions examples/emu_sv_examples/examples/quench_emu_sv.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exclude_lines = [

[tool.flake8]
max-complexity = 18
max-line-length = 110
max-line-length = 100
exclude = """
.git,
.venv,
Expand Down
Loading