Skip to content
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

Deprecate CutQC #527

Merged
merged 24 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67386f1
deprecate cutqc
ibrahim-shehzad Apr 2, 2024
ce89dbe
Deprecate conversion and metrics.
ibrahim-shehzad Apr 2, 2024
6550136
Remove low coverage line from tox.ini
ibrahim-shehzad Apr 2, 2024
659cd83
Update test_cutqc.py
ibrahim-shehzad Apr 2, 2024
588aaf2
Update deprecation message
ibrahim-shehzad Apr 2, 2024
1d17be6
change package name in deprecation messages
ibrahim-shehzad Apr 2, 2024
4a388d3
snapshot
ibrahim-shehzad Apr 2, 2024
08319c3
Edit deprecation messages
ibrahim-shehzad Apr 2, 2024
659b8b4
Remove extraneous backticks
ibrahim-shehzad Apr 3, 2024
b66926a
add release note
ibrahim-shehzad Apr 3, 2024
c8b810f
Edit release note
ibrahim-shehzad Apr 3, 2024
e90fd4d
Update deprecation message in init file
ibrahim-shehzad Apr 4, 2024
2b9aff8
Move the deprecated imports inside the test functions
garrison Apr 4, 2024
66b2425
Skip the doctests in `metrics.py`
garrison Apr 4, 2024
c6bee07
Also avoid importing cutqc during test discovery
garrison Apr 4, 2024
6c57712
Remove warnings from private methods, edit release note and removal t…
ibrahim-shehzad Apr 4, 2024
601628d
Merge branch 'deprecate-cutqc' of https://github.com/Qiskit-Extension…
ibrahim-shehzad Apr 4, 2024
dc31577
Add ignore flags
ibrahim-shehzad Apr 4, 2024
1497412
Correct typo in deprecation message
ibrahim-shehzad Apr 4, 2024
fd5e44e
Edit removal timeline field
ibrahim-shehzad Apr 4, 2024
a9e1bb4
Remove trailing space
ibrahim-shehzad Apr 4, 2024
3f7142b
Double backticks
ibrahim-shehzad Apr 4, 2024
735d9f1
Add backticks around module name
ibrahim-shehzad Apr 4, 2024
2d2c553
restore notebook
ibrahim-shehzad Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions circuit_knitting/cutting/cutqc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

"""Code to initialize the cutqc imports."""

from warnings import warn

from .wire_cutting_evaluation import run_subcircuit_instances
from .wire_cutting_post_processing import generate_summation_terms, build
from .wire_cutting_verification import verify
Expand All @@ -33,3 +35,11 @@
"create_dd_bin",
"reconstruct_dd_full_distribution",
]

warn(
f"The package ``{__name__}`` is deprecated and will be removed no sooner than Circuit Knitting Toolbox v0.8.0. "
"The circuit cutting workflow in ``circuit_knitting.cutting`` now implements similar and improved functionalities, which will be maintained going forward."
" See https://qiskit-extensions.github.io/circuit-knitting-toolbox/circuit_cutting/tutorials/04_automatic_cut_finding.ipynb for a tutorial on the newly added automated cut-finding functionality.",
DeprecationWarning,
stacklevel=2,
)
19 changes: 19 additions & 0 deletions circuit_knitting/cutting/cutqc/dynamic_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@
from typing import Sequence, Any
from qiskit import QuantumCircuit
from qiskit.circuit import Qubit
from qiskit.utils.deprecation import deprecate_func

from .wire_cutting_post_processing import build, find_process_jobs


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def dd_build(
summation_terms: Sequence[dict[int, int]],
subcircuit_entry_probs: dict[int, dict[int, np.ndarray]],
Expand Down Expand Up @@ -414,6 +421,12 @@ def _merge_states_into_bins(
return merged_subcircuit_entry_probs


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def read_dd_bins(
subcircuit_out_qubits: dict[int, list[int]], dd_bins: dict[int, dict[str, Any]]
) -> np.ndarray:
Expand Down Expand Up @@ -483,6 +496,12 @@ def read_dd_bins(
return reconstructed_prob


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def get_reconstruction_qubit_order(
full_circuit: QuantumCircuit,
complete_path_map: dict[Qubit, list[dict[str, int | Qubit]]],
Expand Down
10 changes: 9 additions & 1 deletion circuit_knitting/cutting/cutqc/mip_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import numpy as np

from qiskit.utils.deprecation import deprecate_func


class MIPModel(object):
"""
Expand All @@ -30,6 +32,12 @@ class MIPModel(object):
can find the optimal wire cuts in the circuit.
"""

@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def __init__(
self,
n_vertices: int,
Expand Down Expand Up @@ -95,7 +103,7 @@ def __init__(
from docplex.mp.model import Model
except ModuleNotFoundError as ex: # pragma: no cover
raise ModuleNotFoundError(
"DOcplex is not installed. For automatic cut finding to work, both "
"DOcplex is not installed. For automatic cut-finding to work, both "
"DOcplex and cplex must be available."
) from ex

Expand Down
49 changes: 46 additions & 3 deletions circuit_knitting/cutting/cutqc/wire_cutting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from qiskit.dagcircuit import DAGCircuit, DAGOpNode
from qiskit.converters import circuit_to_dag, dag_to_circuit
from qiskit_ibm_runtime import Options, QiskitRuntimeService
from qiskit.utils.deprecation import deprecate_func

from .wire_cutting_evaluation import run_subcircuit_instances
from .wire_cutting_post_processing import generate_summation_terms, build
Expand All @@ -32,6 +33,12 @@
)


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def cut_circuit_wires(
circuit: QuantumCircuit,
method: str,
Expand Down Expand Up @@ -69,7 +76,7 @@ def cut_circuit_wires(
if method == "automatic":
if max_subcircuit_width is None:
raise ValueError(
"The max_subcircuit_width argument must be set if using automatic cut finding."
"The max_subcircuit_width argument must be set if using automatic cut-finding."
)
cuts = find_wire_cuts(
circuit=circuit,
Expand All @@ -96,6 +103,12 @@ def cut_circuit_wires(
return cuts


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def evaluate_subcircuits(
cuts: dict[str, Any],
service: QiskitRuntimeService | None = None,
Expand Down Expand Up @@ -154,6 +167,12 @@ def evaluate_subcircuits(
return subcircuit_instance_probabilities


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def reconstruct_full_distribution(
circuit: QuantumCircuit,
subcircuit_instance_probabilities: dict[int, dict[int, np.ndarray]],
Expand Down Expand Up @@ -196,6 +215,12 @@ def reconstruct_full_distribution(
return reconstructed_probability


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def create_dd_bin(
subcircuit_instance_probabilities: dict[int, dict[int, np.ndarray]],
cuts: dict[str, Any],
Expand Down Expand Up @@ -235,6 +260,12 @@ def create_dd_bin(
)


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def reconstruct_dd_full_distribution(
circuit: QuantumCircuit,
cuts: dict[str, Any],
Expand Down Expand Up @@ -385,6 +416,12 @@ def _attribute_shots(


@no_type_check
@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def find_wire_cuts(
circuit: QuantumCircuit,
max_subcircuit_width: int,
Expand All @@ -408,7 +445,7 @@ def find_wire_cuts(
max_subcircuit_cuts: Max number of cuts for a subcircuit
max_subcircuit_size: The maximum number of two qubit gates in each
subcircuit
verbose: Whether to print information about the cut finding or not
verbose: Whether to print information about the cut-finding or not

Returns:
The solution found for the cuts
Expand Down Expand Up @@ -489,7 +526,7 @@ def find_wire_cuts(

if best_mip_model is None:
raise ValueError(
"Something went wrong during cut finding. The best MIP model object was never instantiated."
"Something went wrong during cut-finding. The best MIP model object was never instantiated."
)
print("Model objective value = %.2e" % (best_mip_model.objective), flush=True) # type: ignore
print("MIP runtime:", best_mip_model.runtime, flush=True)
Expand All @@ -502,6 +539,12 @@ def find_wire_cuts(
return cut_solution


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def cut_circuit_wire(
circuit: QuantumCircuit, subcircuit_vertices: Sequence[Sequence[int]], verbose: bool
) -> dict[str, Any]:
Expand Down
43 changes: 43 additions & 0 deletions circuit_knitting/cutting/cutqc/wire_cutting_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
import numpy as np

from qiskit import QuantumCircuit
from qiskit.utils.deprecation import deprecate_func
from qiskit.converters import circuit_to_dag, dag_to_circuit
from qiskit.circuit.library.standard_gates import HGate, SGate, SdgGate, XGate
from qiskit.primitives import BaseSampler, Sampler as TestSampler
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Session, Options


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def run_subcircuit_instances(
subcircuits: Sequence[QuantumCircuit],
subcircuit_instances: dict[int, dict[tuple[tuple[str, ...], tuple[Any, ...]], int]],
Expand Down Expand Up @@ -103,6 +110,12 @@ def run_subcircuit_instances(
return subcircuit_instance_probs


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def mutate_measurement_basis(meas: tuple[str, ...]) -> list[tuple[Any, ...]]:
"""
Change of basis for all identity measurements.
Expand Down Expand Up @@ -130,6 +143,12 @@ def mutate_measurement_basis(meas: tuple[str, ...]) -> list[tuple[Any, ...]]:
return mutated_meas_out


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def modify_subcircuit_instance(
subcircuit: QuantumCircuit, init: tuple[str, ...], meas: tuple[str, ...]
) -> QuantumCircuit:
Expand Down Expand Up @@ -210,6 +229,12 @@ def modify_subcircuit_instance(
return subcircuit_instance_circuit


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def run_subcircuits_using_sampler(
subcircuits: Sequence[QuantumCircuit],
sampler: BaseSampler,
Expand Down Expand Up @@ -242,6 +267,12 @@ def run_subcircuits_using_sampler(
return all_probabilities_out


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def run_subcircuits(
subcircuits: Sequence[QuantumCircuit],
service: QiskitRuntimeService | None = None,
Expand Down Expand Up @@ -275,6 +306,12 @@ def run_subcircuits(
return run_subcircuits_using_sampler(subcircuits, sampler)


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def measure_prob(unmeasured_prob: np.ndarray, meas: tuple[Any, ...]) -> np.ndarray:
"""
Compute the effective probability distribution from the subcircuit distribution.
Expand All @@ -298,6 +335,12 @@ def measure_prob(unmeasured_prob: np.ndarray, meas: tuple[Any, ...]) -> np.ndarr
return measured_prob


@deprecate_func(
removal_timeline="no sooner than CKT v0.8.0",
since="0.7.0",
package_name="circuit-knitting-toolbox",
additional_msg="Use the wire cutting or automated cut-finding functionality in the ``circuit_knitting.cutting`` package. ",
)
def measure_state(full_state: int, meas: tuple[Any, ...]) -> tuple[int, int]:
"""
Compute the corresponding effective_state for the given full_state.
Expand Down
Loading