Skip to content

Commit 9e2af33

Browse files
authored
Add the missing drift Hamiltonian to the method run_analytically of Processor (#74)
* add missing drift ham to the analytical calculation
1 parent 5d604ff commit 9e2af33

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/qutip_qip/device/processor.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -693,19 +693,25 @@ def run_analytically(self, init_state=None, qc=None):
693693
694694
Returns
695695
-------
696-
evo_result : :class:`qutip.Result`
697-
An instance of the class
698-
:class:`qutip.Result` will be returned.
696+
U_list: list
697+
A list of propagators obtained for the physical implementation.
699698
"""
700699
if init_state is not None:
701700
U_list = [init_state]
702701
else:
703702
U_list = []
704703
tlist = self.get_full_tlist()
705-
# TODO replace this by get_complete_coeff
706704
coeffs = self.get_full_coeffs()
705+
706+
# Compute drift Hamiltonians
707+
H_drift = 0
708+
for drift_ham in self.drift.drift_hamiltonians:
709+
H_drift += drift_ham.get_qobj(self.dims)
710+
711+
# Compute control Hamiltonians
707712
for n in range(len(tlist)-1):
708-
H = sum([coeffs[m, n] * self.ctrls[m]
713+
H = H_drift + sum(
714+
[coeffs[m, n] * self.ctrls[m]
709715
for m in range(len(self.ctrls))])
710716
dt = tlist[n + 1] - tlist[n]
711717
U = (-1j * H * dt).expm()

tests/test_processor.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,19 @@ def testDrift(self):
320320
Test for the drift Hamiltonian
321321
"""
322322
processor = Processor(N=1)
323-
processor.add_drift(sigmaz(), 0)
324-
tlist = np.array([0., 1., 2.])
325-
processor.add_pulse(Pulse(identity(2), 0, tlist, False))
323+
processor.add_drift(sigmax() / 2, 0)
324+
tlist = np.array([0., np.pi, 2*np.pi, 3*np.pi])
325+
processor.add_pulse(Pulse(None, None, tlist, False))
326326
ideal_qobjevo, _ = processor.get_qobjevo(noisy=True)
327-
assert_equal(ideal_qobjevo.cte, sigmaz())
327+
assert_equal(ideal_qobjevo.cte, sigmax() / 2)
328+
329+
init_state = basis(2)
330+
propagators = processor.run_analytically()
331+
analytical_result = init_state
332+
for unitary in propagators:
333+
analytical_result = unitary * analytical_result
334+
fid = fidelity(sigmax() * init_state, analytical_result)
335+
assert((1 - fid) < 1.0e-6)
328336

329337
def testChooseSolver(self):
330338
# setup and fidelity without noise

0 commit comments

Comments
 (0)