Skip to content

Support wire cutting of QubitCircuit#111

Merged
xiangmind merged 12 commits intoTuringQ:mainfrom
sansiro77:dev-hjj
Sep 18, 2025
Merged

Support wire cutting of QubitCircuit#111
xiangmind merged 12 commits intoTuringQ:mainfrom
sansiro77:dev-hjj

Conversation

@sansiro77
Copy link
Contributor

cir = dq.QubitCircuit(7)
for i in range(7):
    cir.rx(i, np.pi / 4)
cir.cut(6)
cir.cx(0, 3)
cir.cx(1, 3)
cir.cx(2, 3)
cir.cut(3)
cir.cx(3, 4)
cir.cx(3, 5)
cir.cx(3, 6)
cir.cut(3)
cir.cx(0, 3)
cir.cx(1, 3)
cir.cx(2, 3)
cir.observable(6)
cir.observable(3)
cir.observable(0)

subexperiments, coefficients = cir.get_subexperiments()

shots = 1024
expval_total = 0
for i, coeff in enumerate(coefficients):
    expval = torch.ones(3) * coeff
    for label, subcircuits in subexperiments.items():
        subcircuits[i]()
        expval_per_label = subcircuits[i].expectation(shots=shots)
        expval *= expval_per_label
    expval_total += expval
reconstructed_expval = expval_total.sum()

@sansiro77 sansiro77 requested a review from xiangmind September 15, 2025 11:11
@sansiro77 sansiro77 self-assigned this Sep 15, 2025
@sansiro77 sansiro77 added the enhancement New feature or request label Sep 15, 2025
Copy link
Member

@xiangmind xiangmind left a comment

Choose a reason for hiding this comment

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

LGTM.

@xiangmind xiangmind merged commit 48e3aec into TuringQ:main Sep 18, 2025
@sansiro77 sansiro77 deleted the dev-hjj branch September 21, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants