Skip to content

Commit

Permalink
Define max_step separately for CavityQED (#199)
Browse files Browse the repository at this point in the history
The CavityQED processor uses discrete pulses and different gates may vary a lot in terms of the gate time. This often results in a piece of pulses being neglected by the adaptive ODE solver. Ideally, the max_step option should be set as half of the shortest gate time but this information is lost during the compilation and can only be estimated from the compiled pulses. This PR allows the calculation of max_step to be defined for each type of Processor.
  • Loading branch information
BoxiLi committed Apr 17, 2023
1 parent cf8cd75 commit 0716948
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/qutip_qip/device/cavityqed.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ def get_final_circuit_state(self, final_processor_state: Qobj) -> Qobj:
range(1, len(final_processor_state.dims[0]))
)

def _get_max_step(self):
"""
Define the maximal sampling step for the solver.
"""
full_tlist = self.get_full_tlist()
if full_tlist is not None:
# For this model, discrete pulses are used.
# Hence we use half of the gate time as the step size.
return np.min(np.diff(full_tlist)) / 2
else:
return 0.0


class CavityQEDModel(Model):
"""
Expand Down
20 changes: 13 additions & 7 deletions src/qutip_qip/device/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,20 +1200,15 @@ def run_state(
# A better solution is to use the gate, which
# is however, much harder to implement at this stage, see also
# https://github.com/qutip/qutip-qip/issues/184.
full_tlist = self.get_full_tlist()
if full_tlist is not None:
total_circuit_time = (full_tlist)[-1]
else:
total_circuit_time = 0.0
if is_qutip5:
options = kwargs.get("options", qutip.Options())
if options.get("max_step", 0.0) == 0.0:
options["max_step"] = total_circuit_time / 25
options["max_step"] = self._get_max_step()
options["progress_bar"] = False
else:
options = kwargs.get("options", qutip.Options())
if options.max_step == 0.0:
options.max_step = total_circuit_time / 10
options.max_step = self._get_max_step()
options.progress_bar = False
kwargs["options"] = options
# choose solver:
Expand All @@ -1228,6 +1223,17 @@ def run_state(

return evo_result

def _get_max_step(self):
"""
Define the maximal sampling step for the solver.
"""
full_tlist = self.get_full_tlist()
if full_tlist is not None:
total_circuit_time = (full_tlist)[-1]
else:
total_circuit_time = 0.0
return total_circuit_time / 10

def load_circuit(self, qc):
"""
Translate an :class:`.QubitCircuit` to its
Expand Down

0 comments on commit 0716948

Please sign in to comment.