[WIP] Refactor GRAPE: Merged QTRL Code into QuTiP-QOC #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.py
andsrc/qutip_qoc/_crab.py
import qutip_qtrl.logging_utils as logging
logger = logging.get_logger()
logger.debug(...)
statementsself._qtrl.log_level
conditions (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!