Skip to content

Commit

Permalink
Merge pull request #190 from Ericgig/fix.bug.new.solver
Browse files Browse the repository at this point in the history
Fix bug resulting from changing v5's default solver
  • Loading branch information
BoxiLi committed Jan 21, 2023
2 parents e46a87f + f6efebb commit 5710cfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/qutip_qip/device/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,9 @@ def run_state(
else:
total_circuit_time = 0.0
if is_qutip5:
options = kwargs.get("options", qutip.SolverOptions())
if options["max_step"] == 0.0:
options["max_step"] = total_circuit_time / 10
options = kwargs.get("options", qutip.Options())
if options.get("max_step", 0.0) == 0.0:
options["max_step"] = total_circuit_time / 25
else:
options = kwargs.get("options", qutip.Options())
if options.max_step == 0.0:
Expand All @@ -1221,7 +1221,7 @@ def run_state(
)
elif solver == "mcsolve":
evo_result = mcsolve(
H=noisy_qobjevo, psi0=init_state, tlist=tlist, **kwargs
noisy_qobjevo, init_state, tlist=tlist, **kwargs
)

return evo_result
Expand Down
6 changes: 3 additions & 3 deletions src/qutip_qip/qiskit/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def convert_to_hex(count):
)[0]

exp_res_data = ExperimentResultData(
counts=counts, statevector=Statevector(data=np.array(statevector))
counts=counts, statevector=Statevector(data=statevector.full())
)

header = QobjExperimentHeader.from_dict(
Expand Down Expand Up @@ -366,9 +366,9 @@ def _parse_results(

exp_res_data = ExperimentResultData(
counts=counts,
statevector=Statevector(data=np.array(final_state))
statevector=Statevector(data=final_state.full())
if final_state.type == "ket"
else DensityMatrix(data=np.array(final_state)),
else DensityMatrix(data=final_state.full()),
)

header = QobjExperimentHeader.from_dict(
Expand Down
9 changes: 3 additions & 6 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
CircularSpinChain, SCQubits)

from packaging.version import parse as parse_version
if parse_version(qutip.__version__) < parse_version('5.dev'):
from qutip import Options as SolverOptions
else:
from qutip import SolverOptions
from qutip import Options

_tol = 3.e-2

Expand Down Expand Up @@ -126,7 +123,7 @@ def test_numerical_evolution(
init_state = _ket_expaned_dims(state, device.dims)
else:
init_state = state
options = SolverOptions(store_final_state=True, nsteps=50_000)
options = Options(store_final_state=True, nsteps=50_000)
result = device.run_state(init_state=init_state,
analytical=False,
options=options)
Expand Down Expand Up @@ -183,7 +180,7 @@ def test_numerical_circuit(circuit, device_class, kwargs, schedule_mode):
init_state = _ket_expaned_dims(state, device.dims)
else:
init_state = state
options = SolverOptions(store_final_state=True, nsteps=50_000)
options = Options(store_final_state=True, nsteps=50_000)
result = device.run_state(init_state=init_state,
analytical=False,
options=options)
Expand Down

0 comments on commit 5710cfc

Please sign in to comment.