### Common Setup for Rotation Synthesis Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/rotation_synthesis/README.md Sets up the necessary imports and configuration for rotation synthesis examples. Adjust `dps` based on the required precision (`eps`) to balance runtime and accuracy. ```python3 import mpmath import qualtran.rotation_synthesis as rs # 300 digits of precision is enough for eps as low as 10^-30. # for big enough eps (>= 10^-10) prefer dps ~100 to reduce the runtime # A high dps increases the runtime but a low dps risks missing solutions. config = rs.with_dps(300) theta = 0.1 # theta = 0.1 rad eps = mpmath.mpf(1e-8) # epsilon = 1e-8 ``` -------------------------------- ### Instantiate and Draw SelectFirstQuantization Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Example of how to instantiate the `SelectFirstQuantization` bloq and visualize it using `show_bloqs`. ```python from qualtran.bloqs.chemistry.pbc.first_quantization import SelectFirstQuantization num_bits_p = 6 eta = 10 num_atoms = 10 lambda_zeta = 10 sel_first_quant = SelectFirstQuantization(num_bits_p, eta, num_atoms, lambda_zeta) from qualtran.drawing import show_bloqs show_bloqs([sel_first_quant], ['`sel_first_quant`']) ``` -------------------------------- ### Write Example Bloq Data to File Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/ui-export.ipynb Processes bloq examples, generates their musical score data and call graph information, and writes detailed JSON files for each example to the 'ui_export' directory. ```python import json import os from pathlib import Path from qualtran_dev_tools.all_call_graph import get_all_call_graph from qualtran_dev_tools.notebook_specs import NB_BY_SECTION from qualtran import Adjoint, Controlled from qualtran.drawing.musical_score import get_musical_score_data examples = [ example for section in NB_BY_SECTION for notebook_spec in section[1] for bloq_spec in notebook_spec.bloq_specs for example in bloq_spec.examples ] call_graph = get_all_call_graph(examples) def bloq_score(bloq): try: return get_musical_score_data(bloq.decompose_bloq()) except: return None def bloq_name(bloq): if (isinstance(bloq, (Adjoint, Controlled))): return bloq_name(bloq.subbloq) return bloq.__class__.__name__ def write_example(bloq): file_name = f'ui_export/{bloq_name(bloq)}/{bloq_filename(bloq)}' if not os.path.isfile(file_name): bloq_dict = { 'name': str(bloq), 'attrs': bloq_attrs(bloq), 'msd': bloq_score(bloq), 'callees': list( { 'name': bloq_name(child_bloq), 'filename': bloq_filename(child_bloq) } for child_bloq in call_graph.neighbors(bloq) ) } Path(f'ui_export/{bloq_name(bloq)}').mkdir(parents=True, exist_ok=True) with open(file_name, 'w') as f: json.dump(bloq_dict, f, indent=2, cls=BloqEncoder) for bloq, _ in call_graph.nodes.items(): write_example(bloq) ``` -------------------------------- ### QPE Simulation Setup Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/kaiser_window_state.ipynb Set up the necessary components for simulating Quantum Phase Estimation (QPE) with different window functions, including KaiserWindowState. ```python import cirq import numpy as np from qualtran import BloqBuilder, CompositeBloq from qualtran.bloqs.basic_gates import ZPowGate, OneState, OneEffect from qualtran.bloqs.phase_estimation import TextbookQPE, RectangularWindowState, LPResourceState, KaiserWindowState ``` -------------------------------- ### Instantiate and Get Expected Complexity Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/optimization/k_xor_sat/tutorial_planted_noisy_kxor.ipynb Calls the `make_algo_example` function to create a `PlantedNoisyKXOR` bloq and retrieve its expected computational cost. ```python bloq, cost_O_tilde = make_algo_example() ``` -------------------------------- ### Instantiate KikuchiMatrixEntry with Example Instance Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/optimization/k_xor_sat/kikuchi_adjacency_matrix.ipynb Instantiate the `KikuchiMatrixEntry` bloq using a concrete example k-XOR instance and a specific value for `ell`. This is useful for concrete testing and visualization. ```python from qualtran.bloqs.optimization.k_xor_sat.kxor_instance import example_kxor_instance inst = example_kxor_instance() ell = 8 kikuchi_matrix_entry = KikuchiMatrixEntry(inst, ell, entry_bitsize=3) ``` -------------------------------- ### Kinetic Energy Bloq Setup Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/trotter/grid_ham/trotter_costs.ipynb Instantiates and displays the KineticEnergy bloq. Requires importing KineticEnergy and show_bloq. ```python from qualtran.bloqs.chemistry.trotter.grid_ham import KineticEnergy from qualtran.drawing import show_bloq num_elec = 2 num_grid_each_dim = 2*10 + 1 ke_bloq = KineticEnergy(num_elec, num_grid_each_dim) show_bloq(ke_bloq) ``` -------------------------------- ### Initialize GF2MulK with QGF Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/gf_arithmetic/gf2_multiplication.ipynb Instantiate `GF2MulK` using a `QGF` object and a constant. Ensure the `galois` library is installed for `QGF`. ```python from qualtran.bloqs.gf_arithmetic import GF2MulK ``` ```python import galois from qualtran import QGF mx = galois.Poly.Degrees([0, 1, 3]) # x^3 + x + 1 # gf = galois.GF(2, 3, irreducible_poly=mx) const = 5 # x^2 + 1 gf2_multiply_by_constant = GF2MulK(QGF(2, 3, mx), const) ``` -------------------------------- ### Initialize factoring parameters Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/cryptography/rsa/factoring-via-modexp.ipynb Sets the composite number N and its bitsize n for factoring. This is a setup step for classical demonstration. ```python import numpy as np N = 13*17 n = int(np.ceil(np.log2(N))) N, n ``` -------------------------------- ### Pair Potential Bloq Setup and Complexity Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/trotter/grid_ham/trotter_costs.ipynb Instantiates the PairPotential bloq using pre-computed QROM data and prints its complexity. Requires importing PairPotential, build_qrom_data_for_poly_fit, and get_inverse_square_root_poly_coeffs. ```python from qualtran.bloqs.chemistry.trotter.grid_ham import PairPotential from qualtran.bloqs.chemistry.trotter.grid_ham.inverse_sqrt import build_qrom_data_for_poly_fit poly_coeffs = get_inverse_square_root_poly_coeffs() num_elec = 2 num_grid_each_dim = 2*10 + 1 nbits = 6 qrom_data = build_qrom_data_for_poly_fit(2*nbits+2, 15, poly_coeffs) qrom_data = tuple(tuple(int(k) for k in d) for d in qrom_data) pp_bloq = PairPotential(nbits, qrom_data, poly_bitsize=15) print(pp_bloq.t_complexity()) ``` -------------------------------- ### Define ModExp Bloq Examples with @bloq_example Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/Autodoc.ipynb Use the `@bloq_example` decorator to define example instantiations of a bloq class for documentation and testing. The function name should be the variable name preceded by an underscore, and a return type annotation is required. ```python import sympy from qualtran.bloqs.arithmetic.mod_exp import ModExp from qualtran.resource_usage import bloq_example @bloq_example def _modexp_small() -> ModExp: modexp_small = ModExp(base=3, mod=15, exp_bitsize=3, x_bitsize=2048) return modexp_small @bloq_example def _modexp() -> ModExp: modexp = ModExp.make_for_shor(big_n=15 * 17, g=9) return modexp @bloq_example def _modexp_symb() -> ModExp: g, N, n_e, n_x = sympy.symbols('g N n_e, n_x') modexp_symb = ModExp(base=g, mod=N, exp_bitsize=n_e, x_bitsize=n_x) return modexp_symb ``` -------------------------------- ### Define a Bloq Example with @bloq_example Source: https://github.com/quantumlib/qualtran/blob/main/docs/how_to_test_bloqs.md Use the `@bloq_example` decorator to define Bloq instances for testing and documentation. This exposes the bloq for automated testing and other tools. ```python from qualtran import Bloq, bloq_example from attrs import frozen @frozen class MyBloq(Bloq): # ... implementation ... pass @bloq_example def _my_bloq() -> MyBloq: return MyBloq() ``` -------------------------------- ### Create GeneralizedQSP from Polynomial Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/qsp/generalized_qsp.ipynb Constructs a GeneralizedQSP bloq using the `from_qsp_polynomial` class method. This example uses XPowGate and a simple polynomial with coefficients (0.5, 0.5). ```python from qualtran.bloqs.basic_gates import XPowGate gqsp = GeneralizedQSP.from_qsp_polynomial(XPowGate(), (0.5, 0.5)) ``` -------------------------------- ### Potential Energy Bloq Setup and Decomposition Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/trotter/grid_ham/trotter_costs.ipynb Instantiates, decomposes, and displays the PotentialEnergy bloq. Requires importing PotentialEnergy, show_bloq, and show_call_graph. Note that `coeffs_a` is declared but not used in this snippet. ```python from qualtran.bloqs.chemistry.trotter.grid_ham import PotentialEnergy from qualtran.drawing import show_bloq, show_call_graph num_elec = 2 num_grid_each_dim = 2*10 + 1 coeffs_a = [] pe_bloq = PotentialEnergy(num_elec, num_grid_each_dim) show_bloq(pe_bloq.decompose_bloq()) ``` -------------------------------- ### Repeated Flattening Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/composite_bloq.ipynb Applies the `.flatten` method, which repeatedly calls `flatten_once` until no further flattening is possible. This example starts from the original composite bloq and performs two flattening operations. ```python # Note that in this example, we have gone back to the original `three_p` starting composite bloq. # This will perform two flattening operations. show_bloq( three_p.flatten() ) ``` -------------------------------- ### Initialize TextbookQPE with symbolic exponent and window size Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/text_book_qpe.ipynb Creates an instance of TextbookQPE using symbolic variables for the ZPowGate exponent and the window state size. ```python import sympy from qualtran.bloqs.basic_gates import ZPowGate from qualtran.bloqs.phase_estimation import RectangularWindowState, TextbookQPE theta = sympy.Symbol('theta') m_bits = sympy.Symbol('m') textbook_qpe_using_m_bits = TextbookQPE( ZPowGate(exponent=2 * theta), RectangularWindowState(m_bits) ) ``` -------------------------------- ### Instantiate PrepareFirstQuantizationWithProj bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/projectile.ipynb Demonstrates how to create an instance of the PrepareFirstQuantizationWithProj bloq with specified parameters for a quantum chemistry simulation. ```python from qualtran.bloqs.chemistry.pbc.first_quantization.projectile import PrepareFirstQuantizationWithProj num_bits_p = 6 num_bits_n = 8 eta = 10 num_atoms = 10 lambda_zeta = 10 prep_first_quant = PrepareFirstQuantizationWithProj( num_bits_p, num_bits_n, eta, num_atoms, lambda_zeta ) ``` -------------------------------- ### Initialize TextbookQPE with a specific exponent and window size Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/text_book_qpe.ipynb Creates an instance of TextbookQPE with a ZPowGate of exponent 2*0.234 and a RectangularWindowState of size 3. ```python from qualtran.bloqs.basic_gates import ZPowGate from qualtran.bloqs.phase_estimation import RectangularWindowState, TextbookQPE textbook_qpe_small = TextbookQPE(ZPowGate(exponent=2 * 0.234), RectangularWindowState(3)) ``` -------------------------------- ### Count total bloq examples considered Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/tensor-report-card.ipynb Prints the total number of bloq examples that were processed for tensor simulation. ```python print(len(df)) ``` -------------------------------- ### Import Qualtran in Python Source: https://github.com/quantumlib/qualtran/blob/main/docs/index.md Verifies the Qualtran installation by importing the library in a Python interpreter. This should be successful if the installation was correct. ```python import qualtran ``` -------------------------------- ### Install Graphviz using Conda Source: https://github.com/quantumlib/qualtran/blob/main/docs/index.md Installs the Graphviz dependency using Conda, which is required by Qualtran for drawing diagrams. ```sh conda install graphviz ``` -------------------------------- ### Instantiate HamiltonianSimulationByGQSP with Symbolic Parameters Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/hamiltonian_simulation/hamiltonian_simulation_by_gqsp.ipynb Creates an instance of HamiltonianSimulationByGQSP using symbolic variables for time and precision, suitable for resource analysis. ```python import sympy from qualtran.bloqs.chemistry.hubbard_model.qubitization import ( get_walk_operator_for_hubbard_model, ) tau, t, inv_eps = sympy.symbols(r"\tau t \epsilon^{-1}", positive=True) walk_op = get_walk_operator_for_hubbard_model(2, 2, tau, 4 * tau) symbolic_hamsim_by_gqsp = HamiltonianSimulationByGQSP(walk_op, t=t, precision=1 / inv_eps) ``` -------------------------------- ### Install Optional and Developer Dependencies Source: https://github.com/quantumlib/qualtran/blob/main/docs/index.md Installs all optional and developer dependencies for Qualtran, typically used when contributing to the project. ```sh pip install -r dev_tools/requirements/envs/dev.env.txt ``` -------------------------------- ### Install Qualtran from Source Source: https://github.com/quantumlib/qualtran/blob/main/docs/index.md Installs Qualtran from its GitHub repository. This is useful for inspecting the source code or running Jupyter notebooks. ```sh git clone https://github.com/quantumlib/Qualtran.git cd Qualtran/ pip install -e . ``` -------------------------------- ### Instantiate Product Bloq with Properties Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/block_encoding/product.ipynb Create a Product bloq with specified properties like alpha, ancilla_bitsize, and epsilon for its constituent Unitary bloqs. ```python from qualtran.bloqs.basic_gates import Hadamard, TGate from qualtran.bloqs.block_encoding.unitary import Unitary u1 = Unitary(TGate(), alpha=0.5, ancilla_bitsize=2, resource_bitsize=1, epsilon=0.01) u2 = Unitary(Hadamard(), alpha=0.5, ancilla_bitsize=1, resource_bitsize=1, epsilon=0.1) product_block_encoding_properties = Product((u1, u2)) ``` -------------------------------- ### Install Qualtran using pip Source: https://github.com/quantumlib/qualtran/blob/main/docs/index.md Installs the Qualtran library and its dependencies using pip. Ensure you have a working Python environment. ```sh pip install qualtran ``` -------------------------------- ### Instantiate PrepareUVFirstQuantization Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Instantiate the `PrepareUVFirstQuantization` bloq with specified parameters for a quantum chemistry simulation. ```python num_bits_p = 5 eta = 10 num_atoms = 10 lambda_zeta = 10 m_param = 2**8 num_bits_nuc_pos = 16 prepare_uv = PrepareUVFirstQuantization( num_bits_p=num_bits_p, eta=eta, num_atoms=num_atoms, m_param=m_param, lambda_zeta=lambda_zeta, num_bits_nuc_pos=num_bits_nuc_pos, ) ``` -------------------------------- ### Install Latest Qualtran from GitHub Source: https://github.com/quantumlib/qualtran/blob/main/README.md Install the latest version of the Qualtran package directly from the main branch on GitHub using pip. ```shell pip install git+https://github.com/quantumlib/Qualtran ``` -------------------------------- ### Initialize TextbookQPE from precision and delta Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/text_book_qpe.ipynb Creates an instance of TextbookQPE using a symbolic exponent and a RectangularWindowState initialized from precision and delta. ```python import sympy from qualtran.bloqs.basic_gates import ZPowGate from qualtran.bloqs.phase_estimation import RectangularWindowState, TextbookQPE theta = sympy.Symbol('theta') precision, delta = sympy.symbols('n, delta') textbook_qpe_from_precision_and_delta = TextbookQPE( ZPowGate(exponent=2 * theta), RectangularWindowState.from_precision_and_delta(precision, delta), ) ``` -------------------------------- ### Build Standalone CompositeBloq with BloqBuilder Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/Bloqs-Tutorial.ipynb This example shows how to construct a `CompositeBloq` independently of a `Bloq`'s decomposition. It involves instantiating `BloqBuilder`, manually adding registers, adding operations (CNOTs in this case), and finally finalizing the builder to obtain the `CompositeBloq`. ```python bb = BloqBuilder() x = bb.add_register('x', 1) y = bb.add_register('y', 1) x, y = bb.add(CNOT(), control=x, target=y) y, x = bb.add(CNOT(), control=y, target=x) x, y = bb.add(CNOT(), control=x, target=y) cbloq = bb.finalize(x=x, y=y) show_bloq(cbloq) ``` -------------------------------- ### Prepare for Bloq Decomposition Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/Bloqs-Tutorial.ipynb This snippet shows the initial setup for implementing the `build_composite_bloq` method, which is used to define the decomposition of a Bloq into sub-operations. It includes the necessary import and the method signature. ```python from qualtran import BloqBuilder class SwapTwoBits(Bloq): ... def build_composite_bloq(self, bb: BloqBuilder, *, x, y): ... ``` -------------------------------- ### Instantiate KikuchiHamiltonian with example instance Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/optimization/k_xor_sat/kikuchi_block_encoding.ipynb Creates an instance of the KikuchiHamiltonian bloq using a pre-defined example k-XOR-SAT instance and a specified Kikuchi parameter `ell`. ```python from qualtran.bloqs.optimization.k_xor_sat import KikuchiHamiltonian ``` ```python from qualtran.bloqs.optimization.k_xor_sat.kxor_instance import example_kxor_instance inst = example_kxor_instance() ell = 8 kikuchi_matrix = KikuchiHamiltonian(inst, ell) ``` -------------------------------- ### Instantiate PrepareZetaState Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Instantiate the PrepareZetaState bloq with necessary parameters for simulating molecular systems. ```python num_atoms = 10 lambda_zeta = 10 num_bits_nuc_pos = 8 prepare_zeta = PrepareZetaState( num_atoms=num_atoms, lambda_zeta=lambda_zeta, num_bits_nuc_pos=num_bits_nuc_pos ) ``` -------------------------------- ### Define Guiding State Preparation (Python) Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/hamiltonian_simulation/tutorial_guided_hamiltonian.ipynb Defines the `GuidingState` bloq, representing a quantum circuit that uses G gates and maps |0^N>|0^A> to |Ψ>|0^A>. It requires `ArbitraryGate` for its call graph. ```Python from qualtran import Signature, Bloq, SymbolicInt, Register from qualtran.resource_ نظريات import QAny from qualtran.bloqs.util_bloqs import ArbitraryGate from math import ceil, log2 @frozen class GuidingState(Bloq): """Point 2. Quantum circuit that uses G gates and maps |0^N>|0^A> to |Ψ>|0^A>""" N: SymbolicInt A: SymbolicInt G: SymbolicInt @property def signature(self) -> Bloq: return Signature.build(selection=self.N, junk=self.A) def build_call_graph(self, ssa): return {(ArbitraryGate(), self.G)} @property def selection_bitsize(self): return self.N @property def junk_bitsize(self): return self.A @property def selection_registers(self): return (Register('selection', QAny(self.N)),) @property def junk_registers(self): return (Register('junk', QAny(self.A)),) ``` -------------------------------- ### Count bloq examples with tensors Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/tensor-report-card.ipynb Determines and prints the number of bloq examples that contain explicit tensors after flattening, indicated by a positive width value. ```python print(len(df[df['width'] > 0])) ``` -------------------------------- ### Instantiate SelectPauliLCU bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/multiplexers/select_pauli_lcu.ipynb Demonstrates how to create an instance of the SelectPauliLCU bloq. This involves defining the target register size, a list of Pauli strings to be applied, and calculating the required selection bitsize. ```python from qualtran.bloqs.multiplexers.select_pauli_lcu import SelectPauliLCU ``` ```python target_bitsize = 4 us = ['XIXI', 'YIYI', 'ZZZZ', 'ZXYZ'] us = [cirq.DensePauliString(u) for u in us] selection_bitsize = int(np.ceil(np.log2(len(us)))) select_pauli_lcu = SelectPauliLCU(selection_bitsize, target_bitsize, select_unitaries=us) ``` -------------------------------- ### Count successfully flattened bloq examples Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/tensor-report-card.ipynb Calculates and prints the number of bloq examples that were successfully flattened into a tensor network, indicated by a positive flattening duration. ```python print(len(df[df['flat_dur'] > 0])) ``` -------------------------------- ### Instantiate and Visualize CNOT Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/Bloqs-Tutorial.ipynb Demonstrates how to create an instance of the CNOT Bloq and visualize it using `show_bloq`. ```python from qualtran.drawing import show_bloq cnot = CNOT() show_bloq(cnot) ``` -------------------------------- ### Instantiate QFTTextBook with Symbolic Bitsize Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/qft/qft_text_book.ipynb Create an instance of QFTTextBook using a symbolic bitsize. This is beneficial for creating generic circuits that can be later specialized for different qubit counts, enabling symbolic analysis and optimization. ```python n = sympy.symbols('n') symbolic_qft = QFTTextBook(bitsize=n) ``` -------------------------------- ### Retrieve and process bloq examples for tensor simulation Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/tensor-report-card.ipynb Fetches all bloq examples and iterates through them, submitting tensor simulation reports to an executor with a timeout. It skips specific bloqs that cannot be pickled. ```python bes = get_bloq_examples() # Imports to exclude certain bloqs, see following comment from qualtran.bloqs.multiplexers.apply_gate_to_lth_target import ApplyGateToLthQubit ``` ```python exec = ExecuteWithTimeout(timeout=8., max_workers=4) for i, be in enumerate(bes): if be.bloq_cls == ApplyGateToLthQubit: # This bloq uses a lambda function as one of its attributes, which # can't be pickled and used with multiprocessing. continue exec.submit(report_on_tensors, kwargs=dict(name=be.name, cls_name=be.bloq_cls.__name__, bloq=be.make())) records = [] while exec.work_to_be_done: kwargs, record = exec.next_result() #print(kwargs['name'], end=' ', flush=True) print('\r', f'{exec.work_to_be_done:5d} remaining', end='', flush=True) if record is None: records.append({ 'name': kwargs['name'], 'cls': kwargs['cls_name'], 'err': 'Timeout', }) else: records.append(record) import pandas as pd df = pd.DataFrame(records) ``` -------------------------------- ### Instantiate HamiltonianSimulationByGQSP with Concrete Parameters Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/hamiltonian_simulation/hamiltonian_simulation_by_gqsp.ipynb Creates an instance of HamiltonianSimulationByGQSP for the Hubbard model with concrete numerical parameters for time and precision. ```python from qualtran.bloqs.chemistry.hubbard_model.qubitization import ( get_walk_operator_for_hubbard_model, ) walk_op = get_walk_operator_for_hubbard_model(2, 2, 1, 1) hubbard_time_evolution_by_gqsp = HamiltonianSimulationByGQSP(walk_op, t=5, precision=1e-7) ``` -------------------------------- ### Group Bloq Examples with BloqDocSpec Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/Autodoc.ipynb Group bloq class and its examples using `BloqDocSpec` to prepare for automatic documentation generation. This specification is typically located in the module defining the bloq class. ```python from qualtran.resource_usage import BloqDocSpec _MODEXP_DOC = BloqDocSpec( bloq_cls=ModExp, examples=[_modexp_symb, _modexp_small, _modexp], ) ``` -------------------------------- ### Instantiate SelectFirstQuantizationWithProj Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/projectile/projectile.ipynb Instantiates the `SelectFirstQuantizationWithProj` bloq with specified parameters for quantum chemistry simulations. ```python num_bits_p = 6 num_bits_n = 8 eta = 10 num_atoms = 10 lambda_zeta = 10 sel_first_quant = SelectFirstQuantizationWithProj( num_bits_p, num_bits_n, eta, num_atoms, lambda_zeta ) ``` -------------------------------- ### Get Call Graph and Resource Counts Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/rotations/hamming_weight_phasing.ipynb Get the call graph and resource counts for the HammingWeightPhasing bloq using call_graph with a generalizer to ignore split/join operations. This helps in understanding the bloq's decomposition and resource requirements. ```python from qualtran.resource_counting.generalizers import ignore_split_join hamming_weight_phasing_g, hamming_weight_phasing_sigma = hamming_weight_phasing.call_graph(max_depth=1, generalizer=ignore_split_join) show_call_graph(hamming_weight_phasing_g) show_counts_sigma(hamming_weight_phasing_sigma) ``` -------------------------------- ### QPE Simulation with Different Window Functions Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/kaiser_window_state.ipynb Simulates QPE using TextbookQPE with RectangularWindowState, LPResourceState, and KaiserWindowState, comparing their performance. ```python theta = 0.51234 unitary = ZPowGate(2 * theta) n_samples = 100_000 m = 6 x_vals = [x / 2**m for x in range(2**m)] # Textbook QPE qpe_textbook = TextbookQPE(unitary, RectangularWindowState(m)) thetas_textbook = simulate_theta_estimate(qpe_textbook, n_samples) # SinState QPE qpe_sinstate = TextbookQPE(unitary, LPResourceState(m)) thetas_sinstate = simulate_theta_estimate(qpe_sinstate, n_samples) # Kaiser QPE kaiser_window_state = KaiserWindowState.from_precision_and_delta(3, 1e-2) alpha = kaiser_window_state.alpha assert kaiser_window_state.bitsize == m, f'{kaiser_window_state.bitsize}' qpe_kaiser_state = TextbookQPE(unitary, kaiser_window_state) thetas_kaiser_state = simulate_theta_estimate(qpe_kaiser_state, n_samples) ``` -------------------------------- ### Declare a CompositeBloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/Bloqs-Tutorial.ipynb Example of declaring a `CompositeBloq`, which serves as a container for other sub-bloqs. ```python class CNOT(Bloq): ... ``` -------------------------------- ### Initialize Algorithm Summary Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/surface_code/beverland_et_al_model.ipynb Defines the summary of algorithm specifications for resource estimation, including qubit counts and gate numbers. ```python from qualtran.surface_code import AlgorithmSummary, GateCounts qd_alg = AlgorithmSummary( n_algo_qubits = 100, n_logical_gates = GateCounts( rotation=30_100, # Note in the paper the number of measurements # has an extra zero which we assume to be a typo. measurement=1.4e5, ), n_rotation_layers = 501 ) ``` -------------------------------- ### Instantiate QFTTextBook with Numerical Bitsize Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/qft/qft_text_book.ipynb Create an instance of QFTTextBook with a fixed numerical bitsize. This is useful for circuits with a known, constant number of qubits. ```python qft_text_book = QFTTextBook(3) ``` -------------------------------- ### Get Number of Qubits Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/gate_with_registers.ipynb The number of qubits for a GateWithRegisters instance is automatically derived from its registers. ```python # Number of qubits is derived from registers cirq.num_qubits(gate) ``` -------------------------------- ### Get QubitCount for a Decomposed Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/resource_counting/qubit_counts.ipynb Calculates the estimated qubit count for a decomposed bloq directly. ```python cbloq = bloq.decompose_bloq() get_cost_value(cbloq, QubitCount()) ``` -------------------------------- ### Initialize TextbookQPE from standard deviation epsilon Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/text_book_qpe.ipynb Creates an instance of TextbookQPE using a symbolic exponent and a RectangularWindowState initialized from a standard deviation epsilon. ```python import sympy from qualtran.bloqs.basic_gates import ZPowGate from qualtran.bloqs.phase_estimation import RectangularWindowState, TextbookQPE theta = sympy.Symbol('theta') epsilon = sympy.symbols('epsilon') textbook_qpe_from_standard_deviation_eps = TextbookQPE( ZPowGate(exponent=2 * theta), RectangularWindowState.from_standard_deviation_eps(epsilon) ) ``` -------------------------------- ### Get QubitCount for a Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/resource_counting/qubit_counts.ipynb Calculates the estimated qubit count for a given bloq using QubitCount. ```python get_cost_value(bloq, QubitCount()) ``` -------------------------------- ### Visualize PrepareTFirstQuantization Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Visualizes the `PrepareTFirstQuantization` bloq using `show_bloqs`. Ensure `show_bloqs` is imported. ```python from qualtran.drawing import show_bloqs show_bloqs([prepare_t], ['`prepare_t`']) ``` -------------------------------- ### Declare a User-Defined Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/Bloqs-Tutorial.ipynb Example of how a user can define their own Bloq subclass to represent a specific quantum operation. ```python class ShorsAlgorithm(Bloq): ... ``` -------------------------------- ### Initialize Algorithm Summary for Quantum Chemistry Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/surface_code/beverland_et_al_model.ipynb Instantiates an AlgorithmSummary object with parameters specific to a quantum chemistry simulation. This includes the number of algorithm qubits, gate counts (rotation, measurement, Toffoli, T), and the number of rotation layers. ```python chem_alg = AlgorithmSummary( n_algo_qubits=1318, n_logical_gates=GateCounts( rotation=2.06e8, measurement=1.37e9, toffoli=1.35e11, t=5.53e7, ), n_rotation_layers=2.05e8, ) chem_alg ``` -------------------------------- ### Instantiate and display a bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqify_syntax/bloqify-syntactic-sugar.ipynb Demonstrates how to create an instance of the `negate` bloq with a specific signature and display it using `qlt.show_bloq`. ```Python bloq = negate.make(qlt.Signature.build(x=qdt.QInt(4))) qlt.show_bloq(bloq) ``` -------------------------------- ### Get all Bloq Classes Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/bibliography.ipynb Retrieves all available bloq classes from the Qualtran library. This is a foundational step for further analysis. ```python from qualtran_dev_tools.bloq_finder import get_bloq_classes bloq_classes = get_bloq_classes() len(bloq_classes) ``` -------------------------------- ### Instantiate PrepareFirstQuantization Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Instantiates the `PrepareFirstQuantization` bloq with specified parameters. This bloq prepares the state for first-quantized chemistry Hamiltonians. ```python num_bits_p = 6 eta = 10 num_atoms = 10 lambda_zeta = 10 prep_first_quant = PrepareFirstQuantization(num_bits_p, eta, num_atoms, lambda_zeta) ``` -------------------------------- ### Instantiate MinusState Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/basic_gates/states_and_effects.ipynb Instantiates the MinusState object representing the |-> state. No special setup is required beyond importing. ```python from qualtran.bloqs.basic_gates import MinusState minus_state = MinusState() ``` -------------------------------- ### Import PrepareZetaState Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Import the PrepareZetaState bloq from the chemistry module. ```python from qualtran.bloqs.chemistry.pbc.first_quantization.prepare_zeta import PrepareZetaState ``` -------------------------------- ### Instantiate PlusEffect Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/basic_gates/states_and_effects.ipynb Instantiates the PlusEffect object representing the <+| effect. No special setup is required beyond importing. ```python from qualtran.bloqs.basic_gates import PlusEffect plus_effect = PlusEffect() ``` -------------------------------- ### Instantiate PlusState Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/basic_gates/states_and_effects.ipynb Instantiates the PlusState object representing the |+> state. No special setup is required beyond importing. ```python from qualtran.bloqs.basic_gates import PlusState plus_state = PlusState() ``` -------------------------------- ### Define a Composite Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/composite_bloq.ipynb Defines a composite bloq with three parallel subbloqs. This is a starting point for demonstrating flattening. ```python class ThreeParallelBloqs(Bloq): @property def signature(self) -> Signature: return Signature.build(stuff=3) def build_composite_bloq( self, bb: 'BloqBuilder', stuff: 'SoquetT' ) -> Dict[str, 'SoquetT']: stuff = bb.add(TestParallelCombo(), reg=stuff) stuff = bb.add(TestParallelCombo(), reg=stuff) stuff = bb.add(TestParallelCombo(), reg=stuff) return {'stuff': stuff} # Note! We're using `.as_composite_bloq()` to wrap the Bloq # into a compute graph with one node. three_p = ThreeParallelBloqs().as_composite_bloq() show_bloq(three_p) ``` -------------------------------- ### Instantiate Product Bloq with Symbolic Properties Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/block_encoding/product.ipynb Construct a Product bloq using symbolic values for properties like alpha, ancilla_bitsize, and epsilon, useful for symbolic analysis. ```python import sympy from qualtran.bloqs.basic_gates import Hadamard, TGate from qualtran.bloqs.block_encoding.unitary import Unitary alpha1 = sympy.Symbol('alpha1') a1 = sympy.Symbol('a1') eps1 = sympy.Symbol('eps1') alpha2 = sympy.Symbol('alpha2') a2 = sympy.Symbol('a2') eps2 = sympy.Symbol('eps2') product_block_encoding_symb = Product( ( Unitary(TGate(), alpha=alpha1, ancilla_bitsize=a1, epsilon=eps1), Unitary(Hadamard(), alpha=alpha2, ancilla_bitsize=a2, epsilon=eps2), ) ) ``` -------------------------------- ### Custom Bloq with Adjoint Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/Adjoint.ipynb Defines a custom `TStateMaker` bloq and shows its decomposition. This serves as an example for demonstrating adjoint behavior. ```python from functools import cached_property from typing import * from qualtran import BloqBuilder, Bloq, Signature, SoquetT from qualtran.bloqs.basic_gates import TGate, Hadamard class TStateMaker(Bloq): @cached_property def signature(self) -> 'Signature': return Signature.build(x=1) def build_composite_bloq(self, bb: 'BloqBuilder', x: 'SoquetT') -> Dict[str, 'SoquetT']: x = bb.add(Hadamard(), q=x) x = bb.add(TGate(), q=x) return {'x': x} show_bloq(TStateMaker().decompose_bloq()) ``` -------------------------------- ### Instantiate KikuchiNonZeroIndex bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/optimization/k_xor_sat/kikuchi_adjacency_list.ipynb Demonstrates how to instantiate the `KikuchiNonZeroIndex` bloq by providing a kXOR instance, the Kikuchi parameter `ell`, and the sparsity `s`. ```python from qualtran.bloqs.optimization.k_xor_sat import KikuchiNonZeroIndex from qualtran.bloqs.optimization.k_xor_sat.kxor_instance import example_kxor_instance inst = example_kxor_instance() ell = 8 s = inst.brute_force_sparsity(ell) kikuchi_nonzero_index = KikuchiNonZeroIndex(inst, ell, s=s) ``` -------------------------------- ### Get Immediate Children Bloq Counts Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/resource_counting/call_graph.ipynb Obtains a dictionary of immediate children bloqs and their counts using the `bloq_counts()` method. ```python And().bloq_counts() ``` -------------------------------- ### Import PrepareUniformSuperposition Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/state_preparation/prepare_uniform_superposition.ipynb Import the PrepareUniformSuperposition bloq from qualtran.bloqs.state_preparation. ```python from qualtran.bloqs.state_preparation import PrepareUniformSuperposition ``` -------------------------------- ### Re-instantiate RSAPhaseEstimate for Shor's Algorithm Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/cryptography/rsa/rsa.ipynb Demonstrates re-instantiating the RSAPhaseEstimate bloq for Shor's algorithm with the same parameters as a previous example. ```python rsa_pe_shor = RSAPhaseEstimate.make_for_shor(big_n=13 * 17, g=9) ``` -------------------------------- ### Initialize with Symbolic Parameters Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/state_preparation/state_preparation_alias_sampling.ipynb Initialize SparseStatePreparationAliasSampling using symbolic parameters for the number of coefficients, non-zero coefficients, sum of coefficients, and precision. ```python import sympy n_coeffs, n_nonzero_coeffs, sum_coeff, eps = sympy.symbols(r"L d \lambda \epsilon") sparse_state_prep_alias_symb = SparseStatePreparationAliasSampling.from_n_coeff( n_coeffs, n_nonzero_coeffs, sum_coeff, precision=eps ) ``` -------------------------------- ### Import QubitizationQPE Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/phase_estimation/qubitization_qpe.ipynb Import the QubitizationQPE bloq. ```python from qualtran.bloqs.phase_estimation import QubitizationQPE ``` -------------------------------- ### Flatten with Predicate Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/composite_bloq.ipynb Uses an optional predicate to control which subbloqs are decomposed and flattened. This example flattens only the subbloq where the instance index is 1. ```python # Flatten by binst properties show_bloq( flat_three_p.flatten_once(lambda binst: binst.i == 1) ) ``` -------------------------------- ### Get Density Matrix Shape Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/simulation/supertensor.ipynb Displays the shape of the density matrix tensor. This is useful for understanding its dimensionality before reshaping for matrix-vector multiplication. ```python rho_coin_flip.shape ``` -------------------------------- ### Instantiate PrepareTFirstQuantization Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Instantiates the `PrepareTFirstQuantization` bloq with specified bit precision and number of electrons. ```python num_bits_p = 5 eta = 10 prepare_t = PrepareTFirstQuantization(num_bits_p=num_bits_p, eta=eta) ``` -------------------------------- ### Adjoint of ZeroState Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/Adjoint.ipynb Demonstrates how to get and display the adjoint of a ZeroState bloq. This is useful for understanding the adjoint operation on basic gates. ```python from qualtran.drawing import show_bloq from qualtran.bloqs.basic_gates import ZeroState print(ZeroState()) show_bloq(ZeroState()) print(ZeroState().adjoint()) show_bloq(ZeroState().adjoint()) ``` -------------------------------- ### Instantiate ReflectionUsingPrepare Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/reflections/reflections.ipynb Creates an instance of ReflectionUsingPrepare using a provided prepare_gate. This is useful for general state preparation reflections. ```python from qualtran.bloqs.reflections.reflection_using_prepare import ReflectionUsingPrepare from qualtran.bloqs.state_preparation import StatePreparationAliasSampling data = [1] * 5 eps = 1e-2 prepare_gate = StatePreparationAliasSampling.from_probabilities(data, precision=eps) refl_using_prep = ReflectionUsingPrepare(prepare_gate) ``` -------------------------------- ### Traditional `bb.add` vs. `qcall` Syntax Source: https://github.com/quantumlib/qualtran/blob/main/docs/qcall.md Illustrates the difference in syntax between the imperative `bb.add` method and the more concise `qcall` pattern for composing bloqs. ```python q0, q1 = bb.add(CNOT(), ctrl=q0, target=q1) ``` ```python q0, q1 = CNOT.qcall(q0, q1) ``` -------------------------------- ### Get Named Qubits from Signature Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/gate_with_registers.ipynb Use get_named_qubits to allocate a dictionary of cirq.NamedQubit based on the Signature. This is used to turn a Gate into an Operation. ```python from qualtran._infra.gate_with_registers import get_named_qubits r = gate.signature quregs = get_named_qubits(r) quregs ``` -------------------------------- ### Analyze slowest width calculation durations Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/tensor-report-card.ipynb Displays the bloq examples with the longest durations for calculating the tensor network width, sorted by 'width_dur'. ```python # Slowest width_dur df.sort_values(by='width_dur', ascending=False).head() ``` -------------------------------- ### Instantiate and Display ModExp Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/surface_code/msft_resource_estimator_interop.ipynb Initializes the ModExp Bloq for Shor's algorithm and displays its structure. Ensure necessary Qualtran modules are imported. ```python from qualtran.bloqs.cryptography.rsa import ModExp from qualtran.drawing import show_bloq N = 13*17 # integer to factor g = 8 mod_exp = ModExp(base=g, mod=N, exp_bitsize=32, x_bitsize=32) show_bloq(mod_exp) ``` -------------------------------- ### Analyze slowest tensor network construction durations Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/tensor-report-card.ipynb Displays the bloq examples with the longest durations for tensor network construction, sorted by 'tn_dur'. ```python # Slowest tn_dur df.sort_values(by='tn_dur', ascending=False).head() ``` -------------------------------- ### Instantiate PrepareSparse Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/sparse/sparse.ipynb Instantiates the PrepareSparse bloq from Hamiltonian coefficients. Requires pre-calculated coefficients and specifies the number of spin orbitals and state preparation bits. ```python from qualtran.bloqs.chemistry.sparse.prepare_test import build_random_test_integrals num_spin_orb = 6 tpq, eris = build_random_test_integrals(num_spin_orb // 2) prep_sparse = PrepareSparse.from_hamiltonian_coeffs( num_spin_orb, tpq, eris, num_bits_state_prep=4 ) ``` -------------------------------- ### Instantiate GF2PolyAddK with symbolic parameters Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/gf_poly_arithmetic/gf2_poly_add_k.ipynb Creates an instance of GF2PolyAddK with symbolic parameters for degree and field size, and a zero constant polynomial. ```python import sympy from galois import Poly from qualtran import QGF, QGFPoly n, m = sympy.symbols('n, m', positive=True, integers=True) qgf_poly = QGFPoly(n, QGF(2, m)) gf2_poly_add_k_symbolic = GF2PolyAddK(qgf_poly, Poly([0, 0, 0, 0])) ``` -------------------------------- ### Inspect CNOT Unitary Matrix Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/simulation/tensor.ipynb Get the tensor representation of a CNOT gate. This is useful for inspecting the familiar unitary matrix of a quantum operation. ```python from qualtran.bloqs.basic_gates import CNOT cnot = CNOT() cnot.tensor_contract().real ``` -------------------------------- ### Building a CompositeBloq with BloqBuilder Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/_infra/Readme.md Demonstrates the basic usage of BloqBuilder to allocate, operate on, and free quantum variables, finally finalizing into a CompositeBloq. ```python bb = BloqBuilder() q = bb.allocate(1) # allocate a quantum variable. q, = bb.add(H, qubit=q) # wire it into a new `H` op, get new quantum variable back. bb.free(q) # discard our quantum variable, get nothing back. cbloq = bb.finalize() # finish building, turn into a `CompositeBloq` ``` -------------------------------- ### Get Quantum Resource Counts Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/optimization/k_xor_sat/tutorial_planted_noisy_kxor.ipynb Calculates the quantum resource counts (e.g., gate operations, qubits) for the bloq using the `QECGatesCost` metric. ```python from qualtran.resource_counting import get_cost_value, QECGatesCost gc = get_cost_value(bloq, QECGatesCost()) gc.asdict() ``` -------------------------------- ### Get Bloq Report Card Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/bloq-report-card.ipynb Retrieves the bloq report card, which contains information about all bloqs. This is the initial step before querying or displaying reports. ```python from qualtran_dev_tools.bloq_report_card import get_bloq_report_card, show_bloq_report_card, summarize_results report_card = get_bloq_report_card() ``` -------------------------------- ### Import HamiltonianSimulationByGQSP Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/hamiltonian_simulation/hamiltonian_simulation_by_gqsp.ipynb Imports the specific HamiltonianSimulationByGQSP bloq from Qualtran. ```python from qualtran.bloqs.hamiltonian_simulation.hamiltonian_simulation_by_gqsp import HamiltonianSimulationByGQSP ``` -------------------------------- ### Instantiate PairPotential Bloq Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/trotter/grid_ham/trotter.ipynb Demonstrates how to instantiate the PairPotential bloq by providing bitsize, polynomial coefficients (via QROM data), and the precision for these coefficients. ```python bitsize = 7 poly_bitsize = 15 poly_coeffs = get_inverse_square_root_poly_coeffs() qrom_data = build_qrom_data_for_poly_fit(2 * bitsize + 2, poly_bitsize, poly_coeffs) qrom_data = tuple(tuple(int(k) for k in d) for d in qrom_data) pair_potential = PairPotential(bitsize=bitsize, qrom_data=qrom_data, poly_bitsize=poly_bitsize) ``` -------------------------------- ### Instantiate and Visualize QvrZPow Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/rotations/quantum_variable_rotation.ipynb Creates an instance of the QvrZPow Bloq with specified bit size, gamma, and epsilon, and then visualizes it using show_bloqs. ```python qvr_zpow = QvrZPow.from_bitsize(12, gamma=0.1, eps=1e-2) ``` ```python from qualtran.drawing import show_bloqs show_bloqs([qvr_zpow], ['`qvr_zpow`']) ``` -------------------------------- ### Summarize Bloqs in Chemistry Package Source: https://github.com/quantumlib/qualtran/blob/main/dev_tools/bloq-report-card.ipynb Summarizes the bloqs whose package name starts with 'chemistry'. This provides a concise overview of bloqs in this category. ```python summarize_results(report_card.query('package.str.startswith("chemistry")')) ``` -------------------------------- ### Import PrepareUVFirstQuantization Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/chemistry/pbc/first_quantization/first_quantization.ipynb Import the necessary class from the qualtran library. ```python from qualtran.bloqs.chemistry.pbc.first_quantization.prepare_uv import PrepareUVFirstQuantization ``` -------------------------------- ### Construct a symbolic GuidingState Source: https://github.com/quantumlib/qualtran/blob/main/qualtran/bloqs/optimization/k_xor_sat/kikuchi_guiding_state_tutorial.ipynb Constructs a symbolic `GuidingState` for a given `KXorInstance` and a symbolic length `l`. The call graph of the guiding state is then visualized. ```python from qualtran.bloqs.optimization.k_xor_sat.kikuchi_guiding_state import GuidingState c, k = sympy.symbols("c k", positive=True, integer=True) l = c * k guiding_state = GuidingState(inst, l) show_call_graph(guiding_state.call_graph(max_depth=1)[0]) ```