Skip to content

Conversation

@jeffwack
Copy link
Contributor

@jeffwack jeffwack commented May 30, 2025

This is incomplete, but I have made some progress on #116 and have some questions. My strategy was to copy the file QuantumOpticsExt and go line by line to convert to QuantumToolbox. I ran into name collisions (basis and \otimes) come to mind, so I decided to be conservative and use the QuantumToolbox.function() form for all function calls.

I ran into a roadblock converting this:

const xyzopdict = Dict(:X=>_x, :Y=>_y, :Z=>_z)
const xyzstatedict = Dict(:X=>(_s₊,_s₋),:Y=>(_i₊,_i₋),:Z=>(_l0,_l1))
for control in (:X, :Y, :Z)
    for target in (:X, :Y, :Z)
        k1, k2 = xyzstatedict[control]
        o = xyzopdict[target]
        gate = QuantumToolbox.tensor(proj(k1),_id) + QuantumToolbox.tensor(proj(k2),o)
        structname = Symbol(control,"C",target,"Gate")
        let gate=copy(gate)
            @eval express_nolookup(::$(structname), ::QuantumToolboxRepr) = $gate
        end
    end
end

Specifically, you cannot copy() a QuantumToolbox operator. This example shows the error:

using QuantumToolbox
copy(sigmap())

So, to avoid type piracy we cannot implement the conversion as written without contributing a method for copy() to QuantumToolbox?

Another route would be to rework that chunk to avoid the copy, but I am not so clear on how it does what it does. Why the macro?

@codecov
Copy link

codecov bot commented May 30, 2025

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.18%. Comparing base (d11c261) to head (2122383).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
ext/QuantumToolboxExt/QuantumToolboxExt.jl 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #121      +/-   ##
==========================================
- Coverage   76.48%   76.18%   -0.30%     
==========================================
  Files          20       21       +1     
  Lines         842      886      +44     
==========================================
+ Hits          644      675      +31     
- Misses        198      211      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@apkille
Copy link
Member

apkille commented May 30, 2025

Specifically, you cannot copy() a QuantumToolbox operator. This example shows the error:

Could you just print the error here? It makes review and answering questions faster.

Another route would be to rework that chunk to avoid the copy, but I am not so clear on how it does what it does. Why the macro?

Notice that the for loops are iterating through Symbols. Here's a discussion on what @eval does that probably is helpful.

So, to avoid type piracy we cannot implement the conversion as written without contributing a method for copy() to QuantumToolbox?

Yeah, if you do want a new copy method for the QObjs, I would recommend submitting a PR to QuantumToolbox rather than committing type piracy here. Although that's really not necessary, there's a bunch of different ways you could define the express_nolookup methods here. To help understand what the chunk does, note how we do it in actually defining symbolic objects like (XCXGate and ZCYGate) in the source code:

const xyzsuplabeldict = Dict(:X=>"ˣ",:Y=>"ʸ",:Z=>"")
for control in (:X, :Y, :Z)
for target in (:X, :Y, :Z)
structname = Symbol(control,"C",target,"Gate")
label = xyzsuplabeldict[control]*"C"*xyzsuplabeldict[target]
declare = :(@withmetadata struct $structname <: AbstractTwoQubitGate end)
defsymlabel = :(symbollabel(::$structname) = $label)
instancename = Symbol(control,"C",target)
definstance = :(const $instancename = $structname())
eval(declare)
eval(defsymlabel)
eval(definstance)
end
end

When defining the conversion in QuantumOptics, we are looping through each permutation of the two qubit gates and lining them up with the spin operators defined in QuantumOptics.

@ytdHuang
Copy link

ytdHuang commented Jun 9, 2025

@jeffwack @apkille

Hi, I'm one of the developers in QuantumToolbox.jl.

For your information, we have just merged a pull request (qutip/QuantumToolbox.jl#486) to implement copy method for our quantum objects.

This will be available in our next release v0.32.0, which is scheduled maybe next week.

@ytdHuang
Copy link

@jeffwack @apkille

Just an update to you, we have released QuantumToolbox v0.32 (see our ChangeLog)

@apkille
Copy link
Member

apkille commented Jul 16, 2025

@jeffwack what's the status on this PR? I can help you finish it if you want.

@jeffwack
Copy link
Contributor Author

@apkille That sounds great to me! Apologies, I let this fall off my todo list. If you want to take this over that is fine by me :)

@apkille apkille requested a review from Krastanov July 20, 2025 20:32
@apkille apkille marked this pull request as ready for review July 20, 2025 20:32
@apkille
Copy link
Member

apkille commented Jul 20, 2025

@Krastanov should be good to go for review!

@Krastanov
Copy link
Member

looks good to merge once we figure out what the test failures are

we also might want to start having separate test runners for each extension, but this is beyond the scope of this PR

Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just marking it as an actual review:

  • downgrade test
  • changelog
  • some other failing tests that might just be flaky (but checking that any JET tests failurs are unrelated)

Feel free to merge without checking with me once these are resolved, or tag me if they are weird to deal with / unrelated.

@apkille
Copy link
Member

apkille commented Jul 21, 2025

@Krastanov the downgrade test is weird to me/I'm not sure how to deal with it, it looks like a project.toml issue with QuantumToolbox and SciMLOperators:

caused by: Unsatisfiable requirements detected for package SciMLOperators [c0aeaf25]:
 SciMLOperators [c0aeaf25] log:
 ├─possible versions are: 0.1.0-1.3.1 or uninstalled
 ├─restricted to versions 1.3.1 by an explicit requirement, leaving only versions: 1.3.1
 └─restricted by compatibility requirements with QuantumToolbox [6c2fb7c5] to versions: 0.3.0-0.4.0 — no versions left
   └─QuantumToolbox [6c2fb7c5] log:
     ├─possible versions are: 0.5.4-0.32.1 or uninstalled
     ├─restricted to versions 0.32.0 by QuantumSymbolics [efa7fd63], leaving only versions: 0.32.0 or uninstalled
     │ └─QuantumSymbolics [efa7fd63] log:
     │   ├─possible versions are: 0.4.12 or uninstalled
     │   └─QuantumSymbolics [efa7fd63] is fixed to version 0.4.12-dev
     └─restricted to versions * by project [db1e3c79], leaving only versions: 0.32.0
       └─project [db1e3c79] log:
         ├─possible versions are: 0.0.0 or uninstalled
         └─project [db1e3c79] is fixed to version 0.0.0

the other two CI tests look to be unrelated caching issues for QuantumOpticsRepr and CliffordRepr translations.

@Krastanov
Copy link
Member

this seems related qutip/QuantumToolbox.jl#470

@apkille
Copy link
Member

apkille commented Jul 22, 2025

@Krastanov Shall we merge this and create issues for the failing tests and deal with them in future PRs? I can do that this week during JuliaCon.

@Krastanov
Copy link
Member

I think this will be causing actual issues to some folks. I would not be surprised if this issue pops up in a lot of environments that use QuantumSavory.jl. I would prefer to wait at least for a comment from the QuantumToolbox folks, because this might be unfixable without their commitment, and I would prefer not to have a future PR removing this extension.

@apkille
Copy link
Member

apkille commented Jul 22, 2025

Ok, sounds good

@ytdHuang
Copy link

@Krastanov @apkille

Hi guys,

Sorry for the long wait.

We have just released QuantumToolbox v0.34.0 to support SciMLOperators v1.4.

We don't support the versions between SciMLOperators v1 - v1.3 since there exist large extra memory allocations and also some incorrect results (at least for our runtests).

@Krastanov Krastanov closed this Jul 29, 2025
@Krastanov Krastanov reopened this Jul 29, 2025
@Krastanov
Copy link
Member

Wonderful! I closed/reopened the PR to rerun the tests.

@ytdHuang
Copy link

ytdHuang commented Jul 29, 2025

Ahh, the JuliaRegistry Bot is still running lol.

Maybe need a few minutes to get QuantumToolbox v0.34 merged in the registry

@ytdHuang
Copy link

Should be ready

@apkille apkille closed this Jul 30, 2025
@apkille apkille reopened this Jul 30, 2025
@apkille
Copy link
Member

apkille commented Aug 4, 2025

@Krastanov the remaining two failing tests are unrelated to this PR. Shall we merge?

@apkille
Copy link
Member

apkille commented Aug 8, 2025

@Krastanov ping

@apkille
Copy link
Member

apkille commented Aug 11, 2025

OK, will merge in the next day if there's no disagreements between now and then

@Krastanov
Copy link
Member

apologies for the slow responses and thanks for the prompt (generally, do not hesitate to aggressively use "will merge in the next few days if there is no dissent")

@Krastanov
Copy link
Member

The compat for quantuminterface might need to be bumped to make Downgrade happy.

@Krastanov
Copy link
Member

The macos test is just a flaky test

@Krastanov
Copy link
Member

If the Downgrade test works now, feel free to merge. But generally let's avoid merges where non-flaky tests are failing.

@apkille
Copy link
Member

apkille commented Aug 13, 2025

Hmm looks like a compat issue with Gabs, I'll deal with this.

Edit: also some of the failing tests from bff6ce0 are due to this circular dependency SciML/RecursiveArrayTools.jl#477, which has been fixed.

@apkille apkille closed this Aug 13, 2025
@apkille apkille reopened this Aug 13, 2025
@Krastanov
Copy link
Member

The very last bump is a bit annoying. Pushing SymbolicUtils to 3.13 which is actually the cause of this bug of ours #100 -- well, not exactly bug, rather a feature downgrade. But now at least we are consistent on all platforms and do not need to worry about @test vs @test_broken

@Krastanov Krastanov merged commit 94ddf62 into QuantumSavory:main Aug 14, 2025
17 of 21 checks passed
@Krastanov
Copy link
Member

Thanks, everyone! Sorry about the delay on this, it seems we have had a messed up downgrades CI for a while

@apkille
Copy link
Member

apkille commented Aug 15, 2025

Thanks for seeing the downgrade tests through @Krastanov!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants