[WIP] Refactor GRAPE: Merged QTRL Code into QuTiP-QOC#50
[WIP] Refactor GRAPE: Merged QTRL Code into QuTiP-QOC#50Akhils777 wants to merge 3 commits intoqutip:merged_qtrlfrom
Conversation
|
Let's also remove the qutip_qtrl used in qutip-qoc/src/qutip_qoc/pulse_optim.py Lines 8 to 10 in d5ff028 And import cpo from the files you copied. Then it really tests the imported modules. |
|
What is src/qutip_qoc/q2/test_grape.py? Is this a new test? I think it belongs to the tests folder not src. |
|
Hello @Akhils777 , good start. The idea here is to take inspiration from |
|
Hi Rochisha, thanks! Maybe it is easier to first merge this "moving" PR after we confirm that qutip_qtrl is no longer a requirement as an external dependence, and the tests pass. Further changes could be included in separate PR(s). This will make it easier to track the work. Note that this is merging to a development branch, not the main branch; this won't break anything in main. |
This PR begins the process of integrating GRAPE and CRAB from QTRL into QOC.
✔️ What’s done in this PR:
qutip_qtrl.logging_utils) fromsrc/qutip_qoc/_grape.pyandsrc/qutip_qoc/_crab.pyimport qutip_qtrl.logging_utils as logginglogger = logging.get_logger()logger.debug(...)statementsself._qtrl.log_levelconditions (no functional logic changed)Setup:
q2/, inside the QOC repository.This allows us to reference the original code during refactor without losing context.
Cherry-picked from PR #47:
A previously discovered issue in the JAX-compatible infidelity computation for open-system TRACEDIFF fidelity is also addressed here.
Specifically, the original implementation used:
Qobj(diff.data.adjoint(), dims=...)
which failed under JAX tracing due to dimension mismatches and non-JAX-compatible operations like .tr() and .full().
Fix:
I replaced this with a fully JAX-compatible expression:
This avoids any QuTiP methods that break under JAX tracing and accesses the underlying JAX array safely.
Additional Fix (Test Failures):
After raising the PR, the tests failed due to a breaking change in jax==0.6.2, which removed access to jaxlib.xla_extension.PjitFunction used in result.py for JIT type checks.
To fix this, I updated the type-checking logic using:
_jitfun_type = type(jax.jit(lambda x: x))This restored compatibility across JAX versions and fixed the test failures.
Now, both JOPT and GRAPE run correctly for open-system state transfer problems using TRACEDIFF fidelity.
Let me know if you have suggestions or if you’d like this broken down further. Would love to hear your thoughts!