Skip to content

Commit

Permalink
[Emu-SV] tutorial emu-sv and correlation mat performance (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
murogrande authored Jan 24, 2025
1 parent 603e096 commit d086260
Show file tree
Hide file tree
Showing 4 changed files with 682 additions and 14 deletions.
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

0 comments on commit d086260

Please sign in to comment.