Skip to content

Commit

Permalink
Pj/dta2 489/basic active volume costing (#162)
Browse files Browse the repository at this point in the history
* Adding preliminary active volume architecture costing capability

* Enabling running ex_1 and active volume costing improvements

* Updated active volume accounting and cleaned up module

* Major refactor to GraphEstimator and adding LogicalArchitectureModel classes

* Adding a module to handle general magic state factory selection

* Refactor to move LogicalArchitectureModels to own module and creating an AbstractLogicalResourceInfo class

* Updated graph estimator interface and resource info usage throughout package, updated tests, and added tests for new magic state logging

* Added tests to check active_volume compilation lowers graph state creation cost and to check that cycles for multi-T-state-distilleries get accounted for properly

* Fixing style issues

* Minor refactoring to reduce code duplication

* Updated tests to include active volume spatial accounting

* Added tests for substrate scheduler active volume functions and fixed bug in tocks accounting

* Style fixes

* Fixing bug that undercounted T and rotation measurements

* Updated test and added test checking t measurement count

* Fixing testing vestiges and some cleanup

* Fixing issue about code distance not being updated in logical architecure model

* Removing print statements

* Updating usage of logical failure rate info and fixing minor style issues

* Updating name from active volume to all to all

* Updating setup with consistent flake8 style checks and shortening lines

* Fixing handling of case where magic_state_factory is None

* Removing python warning in decoder info that prevented tests from passing

* Fixing typing incompatibility with python versions

* Fixing bug in typing

* Fixing further python3.9 incompatibilities that were missed in local testing

* Removing support for computing T depth

* Updating naming of all to all compiler in example

* Fixing further style issues

* Removing automatic estimator and fixing style issues

* Improving type handling

* Removing some type checks

* Fixing style and type checking issues

* Removing files that rely on Azure QRE and Orquestra.

* Fixing minor black styling issues

* Fixing import ordering

* Fixing missed all-to-all name changes in one test module

* Fixing attribute error from vestige

* Populating total circuit failure rate in openfermion accounting
  • Loading branch information
pediejo authored Dec 20, 2024
1 parent 98c59f9 commit 80b8279
Show file tree
Hide file tree
Showing 47 changed files with 2,008 additions and 1,891 deletions.
11 changes: 8 additions & 3 deletions examples/ex_10_utility_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
get_implementation_compiler,
)
from benchq.decoder_modeling import DecoderModel
from benchq.logical_architecture_modeling.graph_based_logical_architectures import (
TwoRowBusArchitectureModel,
)
from benchq.problem_ingestion.solid_state_hamiltonians.ising import (
generate_ising_hamiltonian_on_cubic_lattice,
generate_ising_hamiltonian_on_kitaev_lattice,
Expand All @@ -35,7 +38,8 @@ def get_resources(lattice_type: str, size: int, decoder_data_file: str):
else:
raise ValueError(f"Lattice type {lattice_type} not supported")

architecture_model = BASIC_SC_ARCHITECTURE_MODEL
hardware_architecture_model = BASIC_SC_ARCHITECTURE_MODEL
logical_architecture_model = TwoRowBusArchitectureModel()

print("Getting algorithm implementation...")
evolution_time = 1
Expand All @@ -58,7 +62,8 @@ def get_resources(lattice_type: str, size: int, decoder_data_file: str):
gsc_resources = estimator.compile_and_estimate(
algorithm_implementation,
implementation_compiler,
architecture_model,
logical_architecture_model,
hardware_architecture_model,
decoder_model,
)

Expand All @@ -68,7 +73,7 @@ def get_resources(lattice_type: str, size: int, decoder_data_file: str):
footprint_resources = openfermion_estimator(
algorithm_implementation.program.num_data_qubits,
num_t=total_t_gates,
architecture_model=architecture_model,
architecture_model=hardware_architecture_model,
hardware_failure_tolerance=hw_tolerance,
decoder_model=decoder_model,
)
Expand Down
14 changes: 13 additions & 1 deletion examples/ex_1_from_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
from qiskit.circuit import QuantumCircuit

from benchq.algorithms.data_structures import AlgorithmImplementation, ErrorBudget
from benchq.compilation.graph_states import get_ruby_slippers_circuit_compiler
from benchq.compilation.graph_states.implementation_compiler import (
get_implementation_compiler,
)
from benchq.logical_architecture_modeling.graph_based_logical_architectures import (
AllToAllArchitectureModel,
TwoRowBusArchitectureModel,
)
from benchq.quantum_hardware_modeling import BASIC_SC_ARCHITECTURE_MODEL
from benchq.resource_estimators.graph_estimator import GraphResourceEstimator

Expand Down Expand Up @@ -44,11 +49,18 @@ def main(file_name):
# Create the estimator object, we can optimize for "Time" or "Space"
estimator = GraphResourceEstimator(optimization="Time", verbose=True)
# Use the default compiler
compiler = get_implementation_compiler()
compiler = get_implementation_compiler(
circuit_compiler=get_ruby_slippers_circuit_compiler(),
destination="single-thread",
)

all_to_all_architecture = AllToAllArchitectureModel()

# Put all the pieces together to get a resource estimate
gsc_resource_estimates = estimator.compile_and_estimate(
algorithm_implementation,
compiler,
all_to_all_architecture,
architecture_model,
)
print("Resource estimation results:")
Expand Down
53 changes: 45 additions & 8 deletions examples/ex_2_time_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from benchq.compilation.graph_states.implementation_compiler import (
get_implementation_compiler,
)
from benchq.logical_architecture_modeling.graph_based_logical_architectures import (
AllToAllArchitectureModel,
TwoRowBusArchitectureModel,
)
from benchq.problem_ingestion import get_vlasov_hamiltonian
from benchq.problem_ingestion.solid_state_hamiltonians.heisenberg import (
generate_1d_heisenberg_hamiltonian,
Expand All @@ -36,15 +40,15 @@


def main():
evolution_time = 5
evolution_time = 4

start_time = time()
# Generating Hamiltonian for a given set of parameters, which
# defines the problem we try to solve.
# measure_time is a utility tool which measures the execution time of
# the code inside the with statement.
with measure_time() as t_info:
N = 3 # Problem size
N = 6 # Problem size

# Get a Vlasov Hamiltonian for simulation
operator = get_vlasov_hamiltonian(N=N, k=2.0, alpha=0.6, nu=0)
Expand All @@ -59,8 +63,11 @@ def main():
with measure_time() as t_info:
algorithm = qsp_time_evolution_algorithm(operator, evolution_time, 1e-3)

# Transpile the circuit to a Clifford+T circuit
cliff_t_algorithm = algorithm.transpile_to_clifford_t()
cliff_t_algorithm = algorithm
print("Circuit generation time:", t_info.total)
print("n qubits in circuit:", algorithm.program.subroutines[0].n_qubits)
print("n qubits in circuit:", cliff_t_algorithm.program.subroutines[0].n_qubits)

# Allows for parallelized compilation. Uses ruby slippers compiler by default.
# The single-thread setting is simplest to use. You can parallelize on a local
Expand All @@ -71,17 +78,47 @@ def main():
circuit_compiler=get_ruby_slippers_circuit_compiler(),
destination="single-thread",
)
estimator = GraphResourceEstimator(optimization="Time", verbose=True)

two_row_architecture = TwoRowBusArchitectureModel()
all_to_all_architecture = AllToAllArchitectureModel()

graph_estimator = GraphResourceEstimator(optimization="Time", verbose=True)

with measure_time() as t_info:
resource_estimate = estimator.compile_and_estimate(
algorithm,
two_row_resource_estimate = graph_estimator.compile_and_estimate(
cliff_t_algorithm,
implementation_compiler,
two_row_architecture,
BASIC_SC_ARCHITECTURE_MODEL,
)
all_to_all_resource_estimate = graph_estimator.compile_and_estimate(
cliff_t_algorithm,
implementation_compiler,
all_to_all_architecture,
BASIC_SC_ARCHITECTURE_MODEL,
)

print("Resource estimation time without synthesis:", t_info.total)
pprint(resource_estimate)
tr_info = two_row_resource_estimate.logical_architecture_resource_info
a2a_info = all_to_all_resource_estimate.logical_architecture_resource_info

print("Two row resource estimate", two_row_resource_estimate)
print("All to all resource estimate", all_to_all_resource_estimate)
print(
"Two row graph state cycles",
tr_info.qec_cycle_allocation.inclusive("graph state prep"),
)
print(
"All to all graph state cycles",
a2a_info.qec_cycle_allocation.inclusive("graph state prep"),
)
print(
"Two row total cycles",
tr_info.qec_cycle_allocation.total,
)
print(
"All to all total cycles",
a2a_info.qec_cycle_allocation.total,
)

print("Total time to estimate resources:", time() - start_time)

Expand Down
88 changes: 0 additions & 88 deletions examples/ex_3_packages_comparison.py

This file was deleted.

11 changes: 9 additions & 2 deletions examples/ex_4_fast_graph_estimates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

from benchq.algorithms.time_evolution import qsp_time_evolution_algorithm
from benchq.decoder_modeling import DecoderModel
from benchq.logical_architecture_modeling.graph_based_logical_architectures import (
TwoRowBusArchitectureModel,
)
from benchq.problem_ingestion.solid_state_hamiltonians.ising import (
generate_ising_hamiltonian_on_triangular_lattice,
)
Expand All @@ -25,7 +28,8 @@


def main() -> None:
architecture_model = DETAILED_ION_TRAP_ARCHITECTURE_MODEL
hardware_architecture_model = DETAILED_ION_TRAP_ARCHITECTURE_MODEL
logical_architecture_model = TwoRowBusArchitectureModel()

with measure_time() as t_info:
lattice_size = 3
Expand All @@ -46,7 +50,10 @@ def main() -> None:

with measure_time() as t_info:
fast_gsc_resources = get_fast_graph_estimate(
algorithm, architecture_model, optimization="Time"
algorithm,
logical_architecture_model,
hardware_architecture_model,
optimization="Time",
)

print("Resource estimation time with GSC:", t_info.total)
Expand Down
Loading

0 comments on commit 80b8279

Please sign in to comment.