Skip to content

Configs

ClassicalConfig

Bases: Config

A ClassicalConfig instance defines the classical part of a SolverConfig.

ATTRIBUTE DESCRIPTION
classical_solver_type

Classical solver type. Defaults to "cplex".

TYPE: str

cplex_maxtime

CPLEX maximum runtime. Defaults to 600s.

TYPE: float

cplex_log_path

CPLEX log path. Default to solver.log.

TYPE: str

Config

Bases: BaseModel, ABC

Pydantic class for configs.

EmbeddingConfig

Bases: Config

A EmbeddingConfig instance defines the embedding part of a SolverConfig.

ATTRIBUTE DESCRIPTION
embedding_method

The type of embedding method used to place atoms on the register according to the QUBO problem. Defaults to EmbedderType.GREEDY.

TYPE: str | EmbedderType | type[BaseEmbedder]

layout_greedy_embedder

Layout type for the greedy embedder method. Defaults to LayoutType.TRIANGULAR.

TYPE: LayoutType | str

blade_steps_per_round

The number of steps for each layer of dimension for BLaDE. Defaults to 200.

TYPE: int

starting_positions

The starting parameters according to the specified dimensions. Defaults to None.

TYPE: Tensor | None

blade_dimensions

A list of dimension degrees to explore one after the other (default is [5, 4, 3, 2, 2, 2]).

TYPE: list[int]

traps

The number of traps on the register. Defaults to DeviceType.ANALOG_DEVICE.value.min_layout_traps.

TYPE: int

spacing

The minimum distance between atoms. Defaults to DeviceType.ANALOG_DEVICE.value.min_atom_distance.

TYPE: float

density

The estimated density of the QUBO matrix. Defaults to None.

TYPE: float

draw_steps

Show generated graph at each step of the optimization. Defaults to False.

TYPE: bool

animation_save_path

If provided, path to save animation. Defaults to None.

TYPE: str | None

PulseShapingConfig

Bases: Config

A PulseShapingConfig instance defines the pulse shaping part of a SolverConfig.

ATTRIBUTE DESCRIPTION
pulse_shaping_method

Pulse shaping method used. Defauts to PulseType.ADIABATIC.

TYPE: str | PulseType | type[BasePulseShaper]

initial_omega_parameters

Default initial omega parameters for the pulse. Defaults to Omega = (5, 10, 5).

TYPE: List[float]

initial_detuning_parameters

Default initial detuning parameters for the pulse. Defaults to delta = (-10, 0, 10).

TYPE: List[float]

re_execute_opt_pulse

Whether to re-run the optimal pulse sequence. Defaults to False.

TYPE: bool

custom_qubo_cost

Apply a different qubo cost evaluation than the default QUBO evaluation defined in qubosolver/pipeline/pulse.py:OptimizedPulseShaper.compute_qubo_cost. Must be defined as: def custom_qubo_cost(bitstring: str, QUBO: torch.Tensor) -> float. Defaults to None, meaning we use the default QUBO evaluation.

TYPE: Callable[[str, Tensor], float]

custom_objective_fn

For bayesian optimization, one can change the output of qubosolver/pipeline/pulse.py:OptimizedPulseShaper.run_simulation to optimize differently. Instead of using the best cost out of the samples, one can change the objective for an average, or any function out of the form cost_eval = custom_objective_fn(bitstrings, counts, probabilities, costs, best_cost, best_bitstring) Defaults to None, which means we optimize using the best cost out of the samples.

TYPE: Callable[[list, list, list, list, float, str], float]

callback_objective

Apply a callback during bayesian optimization. Only accepts one input dictionary created during optimization d = {"x": x, "cost_eval": cost_eval} hence should be defined as: def callback_fn(d: dict) -> None: Defaults to None, which means no callback is applied.

TYPE: Callable[..., None]

SolverConfig

Bases: Config

A SolverConfig instance defines how a QUBO problem should be solved. We specify whether to use a quantum or classical approach, which backend to run on, and additional execution parameters.

ATTRIBUTE DESCRIPTION
config_name

The name of the current configuration. Defaults to ''.

TYPE: str

use_quantum

Whether to solve using a quantum approach (True) or a classical approach (False). Defaults to False.

TYPE: bool

backend

Which underlying backend configuration is used. Defaults to the default BackendConfig using BackendType.QUTIP.

TYPE: BackendConfig

n_calls

Number of calls for the optimization process inside VQA. Defaults to 20. Note the optimizer accepts a minimal value of 12.

TYPE: int

embedding

Embedding part configuration of the solver.

TYPE: EmbeddingConfig

pulse_shaping

Pulse-shaping part configuration of the solver.

TYPE: PulseShapingConfig

classical

Classical part configuration of the solver.

TYPE: ClassicalConfig

num_shots

Number of samples. Defaults to 500.

TYPE: int

do_postprocessing

Whether we apply post-processing (True) or not (False).

TYPE: bool

do_preprocessing

Whether we apply pre-processing (True) or not (False)

TYPE: bool

from_kwargs(**kwargs) classmethod

Create an instance based on entries of other configs.

Note that if any of the keywords ("backend_config", "embedding", "pulse_shaping", "classical") are present in kwargs, the values are taken directly.

RETURNS DESCRIPTION
SolverConfig

An instance from values.

TYPE: SolverConfig

Source code in qubosolver/config.py
@classmethod
def from_kwargs(cls, **kwargs: dict) -> SolverConfig:
    """Create an instance based on entries of other configs.

    Note that if any of the keywords
    ("backend_config", "embedding", "pulse_shaping", "classical")
    are present in kwargs, the values are taken directly.

    Returns:
        SolverConfig: An instance from values.
    """
    # Extract fields from pydantic BaseModel
    backend_config_fields = {k: v for k, v in kwargs.items() if k in BackendConfig.model_fields}
    embedding_fields = {k: v for k, v in kwargs.items() if k in EmbeddingConfig.model_fields}
    pulse_shaping_fields = {
        k: v for k, v in kwargs.items() if k in PulseShapingConfig.model_fields
    }
    classical_fields = {k: v for k, v in kwargs.items() if k in ClassicalConfig.model_fields}

    solver_fields = {
        k: v
        for k, v in kwargs.items()
        if k in cls.model_fields
        and k not in ("backend_config", "embedding", "pulse_shaping", "classical")
    }

    return cls(
        backend_config=(
            BackendConfig(**backend_config_fields)
            if "backend_config" not in kwargs
            else kwargs["backend_config"]
        ),
        embedding=(
            EmbeddingConfig(**embedding_fields)
            if "embedding" not in kwargs
            else kwargs["embedding"]
        ),
        pulse_shaping=(
            PulseShapingConfig(**pulse_shaping_fields)
            if "pulse_shaping" not in kwargs
            else kwargs["pulse_shaping"]
        ),
        classical=(
            ClassicalConfig(**classical_fields)
            if "classical" not in kwargs
            else kwargs["classical"]
        ),
        **solver_fields,
    )

print_specs()

Print specs.

Source code in qubosolver/config.py
def print_specs(self) -> None:
    """Print specs."""
    print(self._specs())