Skip to content

start of QuantumToolboxExt #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

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?

Copy link

codecov bot commented May 30, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 76.16%. Comparing base (a4980ef) to head (d903bfa).

Files with missing lines Patch % Lines
ext/QuantumToolboxExt/QuantumToolboxExt.jl 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #121      +/-   ##
==========================================
- Coverage   76.62%   76.16%   -0.47%     
==========================================
  Files          19       20       +1     
  Lines         830      839       +9     
==========================================
+ Hits          636      639       +3     
- Misses        194      200       +6     

☔ 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 :)

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.

3 participants