Skip to content

Commit

Permalink
Add the missing drift Hamiltonian to the method run_analytically of…
Browse files Browse the repository at this point in the history
… `Processor` (#74)

* add missing drift ham to the analytical calculation
  • Loading branch information
BoxiLi committed Jul 7, 2021
1 parent 5d604ff commit 9e2af33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/qutip_qip/device/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,19 +693,25 @@ def run_analytically(self, init_state=None, qc=None):
Returns
-------
evo_result : :class:`qutip.Result`
An instance of the class
:class:`qutip.Result` will be returned.
U_list: list
A list of propagators obtained for the physical implementation.
"""
if init_state is not None:
U_list = [init_state]
else:
U_list = []
tlist = self.get_full_tlist()
# TODO replace this by get_complete_coeff
coeffs = self.get_full_coeffs()

# Compute drift Hamiltonians
H_drift = 0
for drift_ham in self.drift.drift_hamiltonians:
H_drift += drift_ham.get_qobj(self.dims)

# Compute control Hamiltonians
for n in range(len(tlist)-1):
H = sum([coeffs[m, n] * self.ctrls[m]
H = H_drift + sum(
[coeffs[m, n] * self.ctrls[m]
for m in range(len(self.ctrls))])
dt = tlist[n + 1] - tlist[n]
U = (-1j * H * dt).expm()
Expand Down
16 changes: 12 additions & 4 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,19 @@ def testDrift(self):
Test for the drift Hamiltonian
"""
processor = Processor(N=1)
processor.add_drift(sigmaz(), 0)
tlist = np.array([0., 1., 2.])
processor.add_pulse(Pulse(identity(2), 0, tlist, False))
processor.add_drift(sigmax() / 2, 0)
tlist = np.array([0., np.pi, 2*np.pi, 3*np.pi])
processor.add_pulse(Pulse(None, None, tlist, False))
ideal_qobjevo, _ = processor.get_qobjevo(noisy=True)
assert_equal(ideal_qobjevo.cte, sigmaz())
assert_equal(ideal_qobjevo.cte, sigmax() / 2)

init_state = basis(2)
propagators = processor.run_analytically()
analytical_result = init_state
for unitary in propagators:
analytical_result = unitary * analytical_result
fid = fidelity(sigmax() * init_state, analytical_result)
assert((1 - fid) < 1.0e-6)

def testChooseSolver(self):
# setup and fidelity without noise
Expand Down

0 comments on commit 9e2af33

Please sign in to comment.