Skip to content

Commit

Permalink
Change get_latex_str to get_control_latex
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxiLi committed Oct 25, 2021
1 parent 52cc852 commit dc6b2b6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/qutip_qip/device/cavityqed.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _compute_params(self):
"The rotating-wave approximation might not be valid."
)

def get_latex_str(self):
def get_control_latex(self):
"""
Get the labels for each Hamiltonian.
It is used in the method method :meth:`.Processor.plot_pulses`.
Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qip/device/circuitqed.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _compute_params(self):
# Times 2 because we use -2πZX/4 as operators
self.params["zx_coeff"] = np.asarray(zx_coeff) * 2

def get_latex_str(self):
def get_control_latex(self):
"""
Get the labels for each Hamiltonian.
It is used in the method method :meth:`.Processor.plot_pulses`.
Expand Down
12 changes: 8 additions & 4 deletions src/qutip_qip/device/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def get_control_labels(self):
"""
return self.model.get_control_labels()

def get_latex_str(self):
def get_control_latex(self):
"""
Get the latex string for each Hamiltonian.
It is used in the method :meth:`.Processor.plot_pulses`.
Expand All @@ -290,8 +290,8 @@ def get_latex_str(self):
nested_latex_str : list of dict
E.g.: ``[{"sx": "\sigma_z"}, {"sy": "\sigma_y"}]``.
"""
if hasattr(self.model, "get_latex_str"):
return self.model.get_latex_str()
if hasattr(self.model, "get_control_latex"):
return self.model.get_control_latex()
labels = self.model.get_control_labels()
return [{label: label for label in labels}]

Expand Down Expand Up @@ -754,6 +754,10 @@ def plot_pulses(
-----
:meth:.Processor.plot_pulses` only works for array_like coefficients.
"""
if hasattr(self, "get_operators_labels"):
warnings.warn("Using the get_operators_labels to provide labels "
"for plotting is deprecated. Please use get_control_latex instead.")

# FIXME fix if pulse is not fully defined.
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
Expand All @@ -776,7 +780,7 @@ def plot_pulses(

pulse_ind = 0
axis = []
for i, label_group in enumerate(self.get_latex_str()):
for i, label_group in enumerate(self.get_control_latex()):
for j, (label, latex_str) in enumerate(label_group.items()):
try:
pulse = self.find_pulse(label)
Expand Down
2 changes: 1 addition & 1 deletion src/qutip_qip/device/spinchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _compute_params(self):
computed_params["sxsy"] = _to_array(self.params["sxsy"], num_coupling)
return computed_params

def get_latex_str(self):
def get_control_latex(self):
"""
Get the labels for each Hamiltonian.
It is used in the method method :meth:`.Processor.plot_pulses`.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_cavityqed_model():
assert_array_equal(model.params["w0"], 7.0)
assert_array_equal(model.params["epsmax"], [1.1, 1, 0, 0.8])
assert model.get_control(0) == model.get_control("sx0")
model.get_latex_str()
model.get_control_latex()


@pytest.mark.parametrize(("model_class"), [LinearSpinChain, CircularSpinChain])
Expand All @@ -41,7 +41,7 @@ def test_spinchain_model(model_class):
assert_array_equal(model.params["sz"], 7.0)
assert_array_equal(model.params["sx"], [1.1, 1, 0, 0.8])
assert model.get_control(0) == model.get_control("sx0")
model.get_latex_str()
model.get_control_latex()
assert model.params["t1"] == 10.0


Expand All @@ -57,7 +57,7 @@ def test_scqubits_model():
assert_array_equal(model.params["omega_single"], np.array([0.02] * 3))
assert_array_equal(model.params["alpha"], [-0.02, -0.015, -0.025])
assert model.get_control(0) == model.get_control("sx0")
model.get_latex_str()
model.get_control_latex()


def test_define_model_in_processor():
Expand Down

0 comments on commit dc6b2b6

Please sign in to comment.