`contract_partially` only allows full contraction

Open
#81 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp
Domain
backend

Research direction

Start by locating PauliPropagator::contract_partially and its tests, then trace how build_graph groups Majorana operators and gates into contraction slices. The examples specify that a shorter parameter list should work when contractions are independent, but should raise an error when the final gate cannot be contracted; add coverage for both cases and run the relevant test suite.

Written by the indexing model from the issue text.

Description

enhancement

Right now it seems you can only contract fully or all Majoranas at once. This is not bad per se , but one could think of being able to contract only part of the graph, example:

from monoprop import Circuit, ExpGate, Pauli, PauliOperator, PauliPropagator

# "new possible feature" example
circuit = Circuit(
    [
        ExpGate(PauliOperator({Pauli("X"): 1.0}, num_qubits=4)),
        ExpGate(PauliOperator({Pauli("Z"): 1.0}, num_qubits=4)),
    ]
)

prop = PauliPropagator(PauliOperator({Pauli("YIII"): 1.0}, num_qubits=4), [], cutoff=6)
prop.build_graph(circuit)
# prop.contract_partially([0.4, 0.5], inplace=True) #OK and available currently
prop.contract_partially([0.4], inplace=True)  # throws error

This approach requires one a check: if Majorana operators are correlated but separate d by other gates, you cannot contract with only one parameter (e.g. contraction happens in slices)

from __future__ import annotations

from monoprop import Circuit, ExpGate, Pauli, PauliOperator, PauliPropagator

# "Problematic" example
circuit = Circuit(
    [
        ExpGate(PauliOperator({Pauli("X"): 1.0}, num_qubits=4), 0),
        ExpGate(PauliOperator({Pauli("Z"): 1.0}, num_qubits=4), 1),
        ExpGate(PauliOperator({Pauli("X"): 1.0}, num_qubits=4), 0),
    ]
)

prop = PauliPropagator(PauliOperator({Pauli("YIII"): 1.0}, num_qubits=4), [], cutoff=6)
prop.build_graph(circuit)
# prop.contract_partially([0.4, 0.5], inplace=True) #OK
prop.contract_partially(
    [0.4], inplace=True
)  # should raise error as we can't contract last gate!
Dominant language
C++
Stars
52
Forks
2
Avg merge
1d 2h
Merged PRs (30d)
22

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Algorithmiq/monoprop

All issues in Algorithmiq/monoprop

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.