Skip to content

Commit

Permalink
Remove ckt (#369)
Browse files Browse the repository at this point in the history
* Remove ckt

* Re-introduce v0.3 backwards-compatibility tests

These still work, even with this PR, so let's keep them around
until we have a good reason to break the v0.3 workflow.

* Use hyphens in `metadata_version` call

This call looks up the version of the _package_, which we typically
refer to using hyphens rather than underscores.

With this, we can remove all uses of the string
`circuit_knitting_toolbox` from the repository, with the
exception of the release notes.

---------

Co-authored-by: Jim Garrison <[email protected]>
  • Loading branch information
caleb-johnson and garrison authored Oct 31, 2023
1 parent e8920ad commit ed74a75
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 277 deletions.
3 changes: 0 additions & 3 deletions circuit_knitting_toolbox/README.md

This file was deleted.

27 changes: 0 additions & 27 deletions circuit_knitting_toolbox/__init__.py

This file was deleted.

73 changes: 0 additions & 73 deletions circuit_knitting_toolbox/circuit_cutting/__init__.py

This file was deleted.

62 changes: 0 additions & 62 deletions circuit_knitting_toolbox/entanglement_forging/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
sys.path.insert(0, str(_rootdir))

# The full version, including alpha/beta/rc tags
release = metadata_version("circuit_knitting_toolbox")
release = metadata_version("circuit-knitting-toolbox")
# The short X.Y version
version = ".".join(release.split(".")[:2])

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ notebook-dependencies = [
[tool.hatch.build.targets.wheel]
only-include = [
"circuit_knitting",
"circuit_knitting_toolbox",
]

[tool.autoflake]
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/remove-ckt-path-2386dc156b1ed9ca.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
upgrade:
- |
Removed the ``circuit_knitting_toolbox`` import path. Users should now import from ``circuit_knitting`` instead.
102 changes: 0 additions & 102 deletions test/cutting/test_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,108 +29,6 @@
import pytest


@pytest.mark.filterwarnings("ignore::PendingDeprecationWarning")
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@pytest.mark.skipforcoverage
def test_v0_2_cutting_width_workflow():
"""v0.2 workflow to reduce circuit width through cutting
docs/circuit_cutting/tutorials/gate_cutting_to_reduce_circuit_width.ipynb
"""
import numpy as np
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import PauliList
from qiskit_aer.primitives import Sampler

from circuit_knitting_toolbox.circuit_cutting import (
partition_problem,
execute_experiments,
reconstruct_expectation_values,
)

circuit = EfficientSU2(4, entanglement="linear", reps=2).decompose()
circuit.assign_parameters([0.8] * len(circuit.parameters), inplace=True)
observables = PauliList(["ZZII", "IZZI", "IIZZ", "XIXI", "ZIZZ", "IXIX"])
subcircuits, bases, subobservables = partition_problem(
circuit=circuit, partition_labels="AABB", observables=observables
)
assert np.prod([basis.overhead for basis in bases]) == pytest.approx(81)

samplers = {
"A": Sampler(run_options={"shots": 1}),
"B": Sampler(run_options={"shots": 1}),
}
quasi_dists, coefficients = execute_experiments(
circuits=subcircuits,
subobservables=subobservables,
num_samples=1500,
samplers=samplers,
)
simulated_expvals = reconstruct_expectation_values(
quasi_dists,
coefficients,
subobservables,
)
assert len(simulated_expvals) == len(observables)


@pytest.mark.filterwarnings("ignore::PendingDeprecationWarning")
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@pytest.mark.skipforcoverage
def test_v0_2_cutting_depth_workflow():
"""v0.2 workflow to reduce circuit depth through cutting
docs/circuit_cutting/tutorials/gate_cutting_to_reduce_circuit_depth.ipynb
"""
import numpy as np
from qiskit import transpile
from qiskit.circuit.library import EfficientSU2
from qiskit_aer.primitives import Sampler
from qiskit.providers.fake_provider import FakeHanoiV2 as FakeHanoi
from qiskit.quantum_info import PauliList

from circuit_knitting_toolbox.circuit_cutting import (
decompose_gates,
execute_experiments,
reconstruct_expectation_values,
)

circuit = EfficientSU2(num_qubits=4, entanglement="circular").decompose()
circuit.assign_parameters([0.8] * len(circuit.parameters), inplace=True)
observables = PauliList(["ZZII", "IZZI", "IIZZ", "XIXI", "ZIZZ", "IXIX"])
backend = FakeHanoi()
transpile(circuit, backend=backend, initial_layout=[0, 1, 2, 3])
cut_indices = [
i
for i, instruction in enumerate(circuit.data)
if {circuit.find_bit(q)[0] for q in instruction.qubits} == {0, 3}
]
# Decompose distant CNOTs into TwoQubitQPDGate instances
qpd_circuit, bases = decompose_gates(circuit, cut_indices)
assert np.prod([basis.overhead for basis in bases]) == pytest.approx(729)
from circuit_knitting_toolbox.circuit_cutting.qpd import decompose_qpd_instructions

for idx in cut_indices:
qpd_circuit[idx].operation.basis_id = 2
qpd_circuit_dx = decompose_qpd_instructions(
qpd_circuit, [[idx] for idx in cut_indices]
)
transpile(qpd_circuit_dx, backend=backend, initial_layout=[0, 1, 2, 3])
sampler = Sampler(run_options={"shots": 1})
quasi_dists, coefficients = execute_experiments(
circuits=qpd_circuit,
subobservables=observables,
num_samples=1500,
samplers=sampler,
)
simulated_expvals = reconstruct_expectation_values(
quasi_dists,
coefficients,
observables,
)
assert len(simulated_expvals) == len(observables)


@pytest.mark.filterwarnings("ignore::PendingDeprecationWarning")
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@pytest.mark.skipforcoverage
Expand Down
16 changes: 8 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ commands =
extras =
style
commands =
ruff check --fix circuit_knitting/ circuit_knitting_toolbox/ docs/ test/ tools/
ruff check --fix circuit_knitting/ docs/ test/ tools/
nbqa ruff --fix docs/
autoflake --in-place --recursive circuit_knitting/ circuit_knitting_toolbox/ docs/ test/ tools/
black circuit_knitting/ circuit_knitting_toolbox/ docs/ test/ tools/
autoflake --in-place --recursive circuit_knitting/ docs/ test/ tools/
black circuit_knitting/ docs/ test/ tools/

[testenv:lint]
basepython = python3.10
extras =
lint
commands =
ruff check circuit_knitting/ circuit_knitting_toolbox/ docs/ test/ tools/
ruff check circuit_knitting/ docs/ test/ tools/
nbqa ruff docs/
autoflake --check --quiet --recursive circuit_knitting/ circuit_knitting_toolbox/ docs/ test/ tools/
black --check circuit_knitting/ circuit_knitting_toolbox/ docs/ test/ tools/
pydocstyle circuit_knitting/ circuit_knitting_toolbox/
mypy circuit_knitting/ circuit_knitting_toolbox/
autoflake --check --quiet --recursive circuit_knitting/ docs/ test/ tools/
black --check circuit_knitting/ docs/ test/ tools/
pydocstyle circuit_knitting/
mypy circuit_knitting/
reno lint
pylint -rn --py-version=3.8 --disable=all --enable=reimported,no-self-use,no-else-raise,redefined-argument-from-local,redefined-builtin,raise-missing-from,cyclic-import,unused-argument circuit_knitting/ test/ tools/
nbqa pylint -rn --py-version=3.8 --disable=all --enable=reimported,no-self-use,no-else-raise,redefined-argument-from-local,redefined-builtin,raise-missing-from,cyclic-import,unused-argument docs/
Expand Down

0 comments on commit ed74a75

Please sign in to comment.