Skip to content

Commit

Permalink
remove the restriction on tlist in processor
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxiLi committed May 1, 2021
1 parent a0f5c0f commit cb1e4f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 18 additions & 6 deletions src/qutip_qip/device/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,17 @@ def run_state(self, init_state=None, analytical=False, states=None,
Old API, same as init_state.
solver: str
"mesolve" or "mcsolve"
"mesolve" or "mcsolve",
for :func:`~qutip.mesolve` and :func:`~qutip.mcsolve`.
noisy: bool
Include noise or not.
**kwargs
Keyword arguments for the qutip solver.
E.g `tlist` for time points for recording
intermediate states and expectation values;
`args` for the solvers and `qutip.QobjEvo`.
Returns
-------
Expand Down Expand Up @@ -753,10 +760,10 @@ def run_state(self, init_state=None, analytical=False, states=None,
"any keyword arguments.")
return self.run_analytically(init_state=init_state)

# kwargs can not contain H or tlist
if "H" in kwargs or "tlist" in kwargs:
# kwargs can not contain H
if "H" in kwargs:
raise ValueError(
"`H` and `tlist` are already specified by the processor "
"`H` is already specified by the processor "
"and can not be given as a keyword argument")

# construct qobjevo for unitary evolution
Expand All @@ -776,14 +783,19 @@ def run_state(self, init_state=None, analytical=False, states=None,
kwargs["c_ops"] = sys_c_ops

# choose solver:
if "tlist" in kwargs:
tlist = kwargs["tlist"]
del kwargs["tlist"]
else:
tlist=noisy_qobjevo.tlist
if solver == "mesolve":
evo_result = mesolve(
H=noisy_qobjevo, rho0=init_state,
tlist=noisy_qobjevo.tlist, **kwargs)
tlist=tlist, **kwargs)
elif solver == "mcsolve":
evo_result = mcsolve(
H=noisy_qobjevo, psi0=init_state,
tlist=noisy_qobjevo.tlist, **kwargs)
tlist=tlist, **kwargs)

return evo_result

Expand Down
10 changes: 8 additions & 2 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,11 @@ def testChooseSolver(self):
fidelity(result.states[-1], qubit_states(2, [0, 1, 0, 0])),
1, rtol=1.e-7)

if __name__ == "__main__":
run_module_suite()
def test_no_saving_intermidiate_state(self):
processor = Processor(1)
processor.add_pulse(pulse=
Pulse(sigmax(), coeff=np.ones(10),
tlist=np.linspace(0,1,10), targets=0)
)
result = processor.run_state(basis(2,0), tlist=[0,1])
assert(len(result.states) == 2)

0 comments on commit cb1e4f6

Please sign in to comment.