Skip to content

Commit

Permalink
Remove quantum_serverless from circuit cutting source code
Browse files Browse the repository at this point in the history
* Remove quantum_serverless from cutting source code

* Fix linter errors

* Modify language in CC tutorial 3

* Fix linter error

* Small edits and fix typos (#33)

* Change to functional workflow in all circuit cutting tutorials

* Fix bad notebook output in CC tutorial 2

* Capture output from MIP model in CC tutorials

* update 3 cutting tutorials

* add manual cutting fig

* Fix conflicts between divergent branches

* Create an img directory in cutting tutorials dir

* Clean up output that is rendering poorly on Github

* Fix linter errors

* Fix broken links in CC tutorials

* Add circuit cutting tutorial README

* Update README.md

Co-authored-by: Jen Glick <[email protected]>
Co-authored-by: Jen <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2022
1 parent 508bcb3 commit 4fafcef
Show file tree
Hide file tree
Showing 10 changed files with 954 additions and 1,044 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Options,
QiskitRuntimeService,
)
from quantum_serverless import run_qiskit_remote, get

from .wire_cutting import find_wire_cuts, cut_circuit_wire
from .wire_cutting_evaluation import run_subcircuit_instances
Expand Down Expand Up @@ -148,7 +147,7 @@ def decompose(
"A circuit must be passed to WireCutter before decompose() is called."
)

cuts_futures = cut_circuit_wires(
cuts = cut_circuit_wires(
self.circuit,
method,
subcircuit_vertices=subcircuit_vertices,
Expand All @@ -158,7 +157,6 @@ def decompose(
max_subcircuit_cuts=max_subcircuit_cuts,
max_subcircuit_size=max_subcircuit_size,
)
cuts = get(cuts_futures)

return cuts

Expand All @@ -173,13 +171,12 @@ def evaluate(self, cuts: Dict[str, Any]) -> Dict[int, Dict[int, NDArray]]:
- (Dict): the dictionary containing the results from running
each of the subcircuits
"""
subcircuit_probability_futures = evaluate_subcircuits(
subcircuit_instance_probabilities = evaluate_subcircuits(
cuts,
self._service,
self._backend_names,
self._options,
)
subcircuit_instance_probabilities = get(subcircuit_probability_futures)

return subcircuit_instance_probabilities

Expand All @@ -202,13 +199,12 @@ def reconstruct(
- (NDArray): the reconstructed probability vector
"""
reconstructed_probability_futures = reconstruct_full_distribution(
reconstructed_probabilities = reconstruct_full_distribution(
circuit=self.circuit,
subcircuit_instance_probabilities=subcircuit_instance_probabilities,
cuts=cuts,
num_threads=num_threads,
)
reconstructed_probabilities = get(reconstructed_probability_futures)

return reconstructed_probabilities

Expand Down Expand Up @@ -238,7 +234,6 @@ def verify(
return metrics, real_probabilities


@run_qiskit_remote()
def cut_circuit_wires(
circuit: QuantumCircuit,
method: str,
Expand Down Expand Up @@ -298,7 +293,6 @@ def cut_circuit_wires(
return cuts


@run_qiskit_remote()
def evaluate_subcircuits(
cuts: Dict[str, Any],
service_args: Optional[Dict[str, Any]] = None,
Expand Down Expand Up @@ -331,7 +325,6 @@ def evaluate_subcircuits(
return subcircuit_instance_probabilities


@run_qiskit_remote()
def reconstruct_full_distribution(
circuit: QuantumCircuit,
subcircuit_instance_probabilities: Dict[int, Dict[int, NDArray]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""Contains functions for executing subcircuits."""
import itertools, copy
from typing import Dict, Tuple, Sequence, Optional, List, Any, Union
from multiprocessing import Pool

import numpy as np
from nptyping import NDArray
Expand All @@ -21,7 +22,6 @@
from qiskit.circuit.library.standard_gates import HGate, SGate, SdgGate, XGate
from qiskit.primitives import Sampler as TestSampler
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Session, Options
from quantum_serverless import run_qiskit_remote, get

from circuit_knitting_toolbox.utils.conversion import dict_to_array

Expand Down Expand Up @@ -63,19 +63,21 @@ def run_subcircuit_instances(
backend_names_repeated = [None] * len(subcircuits)

subcircuit_instance_probs: Dict[int, Dict[int, NDArray]] = {}
subcircuit_instance_probs_futures = [
_run_subcircuit_batch(
subcircuit_instances[subcircuit_idx],
subcircuit,
service_args=service_args,
backend_name=backend_names_repeated[subcircuit_idx],
options=options,
)
for subcircuit_idx, subcircuit in enumerate(subcircuits)
]

for i, partition_batch_futures in enumerate(subcircuit_instance_probs_futures):
subcircuit_instance_probs[i] = get(partition_batch_futures)
with Pool() as pool:
args = [
[
subcircuit_instances[subcircuit_idx],
subcircuit,
service_args,
backend_names_repeated[subcircuit_idx],
options,
]
for subcircuit_idx, subcircuit in enumerate(subcircuits)
]
subcircuit_instance_probs_list = pool.starmap(_run_subcircuit_batch, args)

for i, partition_batch in enumerate(subcircuit_instance_probs_list):
subcircuit_instance_probs[i] = partition_batch

return subcircuit_instance_probs

Expand Down Expand Up @@ -280,7 +282,6 @@ def measure_state(full_state: int, meas: Tuple[Any, ...]) -> Tuple[int, int]:
return sigma, effective_state


@run_qiskit_remote()
def _run_subcircuit_batch(
subcircuit_instance: Dict[Tuple[Tuple[str, ...], Tuple[Any, ...]], int],
subcircuit: QuantumCircuit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
from qiskit.opflow import ListOp, PauliSumOp
from qiskit.quantum_info import Pauli
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.drivers.second_quantization import (
ElectronicStructureDriver,
)
from qiskit_nature.drivers.second_quantization import ElectronicStructureDriver
from qiskit_nature.mappers.second_quantization import JordanWignerMapper
from qiskit_nature.problems.second_quantization import ElectronicStructureProblem
from qiskit_nature.properties.second_quantization.electronic.bases import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
from qiskit import QuantumCircuit
from qiskit.quantum_info import Pauli
from qiskit.primitives import Estimator as TestEstimator
from qiskit_ibm_runtime import (
QiskitRuntimeService,
)
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime.estimator import EstimatorResultDecoder
from quantum_serverless import get, run_qiskit_remote

Expand Down
5 changes: 5 additions & 0 deletions docs/circuit_cutting/tutorials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tutorials

- [Tutorial 1](https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/blob/main/docs/circuit_cutting/tutorials/tutorial_1_automatic_cut_finding.ipynb): Perform circuit cutting with automated cut finding, using a mixed-integer programming model.
- [Tutorial 2](https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/blob/main/docs/circuit_cutting/tutorials/tutorial_2_manual_cutting.ipynb): Perform circuit cutting by manually specifying wire cut locations.
- [Tutorial 3](https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/blob/main/docs/circuit_cutting/tutorials/tutorial_3_cutting_with_quantum_serverless.ipynb): Use Quantum Serverless to allocate steps of the circuit cutting workflow to various compute resources (e.g., the cloud).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4fafcef

Please sign in to comment.