Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
JDTeske committed May 24, 2022
2 parents bd9f20f + 3a166f8 commit 0def9c9
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 70 deletions.
75 changes: 55 additions & 20 deletions doc/source/examples/phase_noise.ipynb

Large diffs are not rendered by default.

48 changes: 23 additions & 25 deletions doc/source/qopt_features/filter_functions_basic.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions patch_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,13 @@ now focuses on the matrix exponentials.

Transfer Function:
- Fixes an assertion controlling the common shape in the ParallelTF

### Version 1.3.1 to 1.3.2

Filter Functions:
- adapt to the latest version of filter functions. The noise operators are not
stored in lexicographic order any more.
- now requires filter_function v1.1.2

Energy Spectrum:
- scatter options can now be given to the plotting function.
14 changes: 5 additions & 9 deletions qopt/cost_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,6 @@ class OperatorFilterFunctionInfidelity(CostFunction):
"""
Calculates the infidelity with the filter function formalism.
ATTENTION: The filter function package sorts the noise operators in
lexicographic order! The order chosen in the `filter_function_h_n` must
correspond to the order in `filter_function_n_coeffs_deriv` and
the one in `noise_power_spec_density`.
Parameters
----------
solver: `Solver`
Expand All @@ -1543,9 +1538,8 @@ class OperatorFilterFunctionInfidelity(CostFunction):
case, the same spectrum is taken for all noise operators, in the
second, it is assumed that there are no correlations between different
noise sources and thus there is one spectrum for each noise operator.
ATTENTION: The filter function package sorts the noise operators in
lexicographic order! The order chosen in the `filter_function_h_n` must
correspond to the order in `noise_power_spec_density`
The order of the noise terms must correspond to the order defined in
the solver by filter_function_h_n.
omega: Sequence[float]
The frequencies at which the integration is to be carried out.
Expand Down Expand Up @@ -1593,7 +1587,8 @@ def costs(self) -> Union[float, np.ndarray]:
pulse=self.solver.pulse_sequence,
spectrum=self.noise_power_spec_density(self.omega),
omega=self.omega,
cache_intermediates=True
cache_intermediates=True,
n_oper_identifiers=self.solver.filter_function_n_oper_identifiers,
)
return infidelity

Expand All @@ -1618,6 +1613,7 @@ def grad(self):
spectrum=self.noise_power_spec_density(self.omega),
omega=self.omega,
control_identifiers=c_id,
n_oper_identifiers=self.solver.filter_function_n_oper_identifiers,
n_coeffs_deriv=self.solver.filter_function_n_coeffs_deriv_vals
)
# what comes from ff:
Expand Down
6 changes: 4 additions & 2 deletions qopt/energy_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def vector_color_map(vectors: np.array):
def plot_energy_spectrum(hamiltonian: List[OperatorMatrix],
x_val: np.array,
x_label: str,
ax=None):
ax=None,
**scatter_kwargs):
"""
Calculates and plots the energy spectra of hamilton operators.
Expand Down Expand Up @@ -111,6 +112,7 @@ def plot_energy_spectrum(hamiltonian: List[OperatorMatrix],
_, ax = plt.subplots()
for i in range(d):
ax.scatter(x=x_val, y=eigenvalues[:, i],
c=vector_color_map(eigenvectors[:, :, i]))
c=vector_color_map(eigenvectors[:, :, i]),
**scatter_kwargs)
ax.set_xlabel(x_label)
return ax
42 changes: 29 additions & 13 deletions qopt/solver_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,7 @@ class Solver(ABC):
the argument can be a callable. This should have the signature of three
input arguments, which are (Optimization parameters, transferred
parameters, control amplitudes). The callable should return an nested
list of the form given above. If not every
sublist (read operator) was given a identifier, they are automatically
filled up with 'A_i' where i is the position of the operator.
Alternatively the create_ff_h_n may be a function handle creating
such an object when called with the optimization parameters.
ATTENTION: The filter function package sorts the noise operators in
lexicographic order! The order chosen in the `filter_function_h_n` must
correspond to the order in `filter_function_n_coeffs_deriv`,
list of the form given above.
filter_function_basis: Basis, shape (d**2, d, d), optional
The operator basis in which to calculate. If a Generalized Gell-Mann
Expand All @@ -142,9 +135,8 @@ class Solver(ABC):
the filter function formalism. It receives the optimization parameters
as array of shape (num_opt, num_t) and returns the derivatives as array
of shape (num_noise_op, n_ctrl, num_t).
ATTENTION: The filter function package sorts the noise operators in
lexicographic order! The order chosen in the `filter_function_h_n` must
correspond to the order in `filter_function_n_coeffs_deriv`,
The order of the noise operators must correspond to the order specified
by filter_function_h_n.
exponential_method: string, optional
Method used by the ControlMatrix class for the calculation of the
Expand Down Expand Up @@ -316,6 +308,11 @@ def __init__(
self._filter_function_h_n = []
else:
self._filter_function_h_n = filter_function_h_n

# we store the order of the noise operators. They must coincide with
# the order in filter_functions_n_coeffs_deriv
self.filter_function_n_oper_identifiers = []

self.filter_function_basis = filter_function_basis
self.filter_function_n_coeffs_deriv = filter_function_n_coeffs_deriv

Expand Down Expand Up @@ -589,8 +586,27 @@ def create_ff_h_n(self) -> list:
h_n = self._filter_function_h_n(self._ctrl_amps)

if not h_n:
h_n = [[np.zeros(self.h_ctrl[0].shape),
np.zeros((len(self.transferred_time),))]]
h_n = []

# we store the order of the noise operators. They must coincide with
# the order in filter_functions_n_coeffs_deriv
self.filter_function_n_oper_identifiers = []
for noise_term in h_n:
if not len(noise_term) == 3:
raise ValueError(
"The noise operators for the filter function must be given"
"as nested list of the form: \n"
"H = [[n_oper1, n_coeff1, n_oper_identifier1], \n"
"[n_oper2, n_coeff2, n_oper_identifier2], ...] \n"
"but not every element of the list you defined has three"
"elements."
)
if not type(noise_term[2]) == str:
raise ValueError(
"The identifiers for the noise terms must be given as "
"string."
)
self.filter_function_n_oper_identifiers.append(noise_term[2])

return h_n

Expand Down
3 changes: 2 additions & 1 deletion qopt_tests/integration_tests/test_t1_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def create_ff_simulator(low_freq_rel, ff_n_time_steps):

ff_hamiltonian_noise = [[
.5 * DenseOperator.pauli_z().data,
np.ones(ff_n_time_steps)
np.ones(ff_n_time_steps),
'Noise 1'
], ]

ff_solver = SchroedingerSolver(
Expand Down

0 comments on commit 0def9c9

Please sign in to comment.