tensorcircuit.applications.dqas#
Modules for DQAS framework
- tensorcircuit.applications.dqas.DQAS_search(kernel_func: Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]], *, g: Optional[Iterator[Any]] = None, op_pool: Optional[Sequence[Any]] = None, p: Optional[int] = None, p_nnp: Optional[int] = None, p_stp: Optional[int] = None, batch: int = 300, prethermal: int = 0, epochs: int = 100, parallel_num: int = 0, verbose: bool = False, verbose_func: Optional[Callable[[], None]] = None, history_func: Optional[Callable[[], Any]] = None, prob_clip: Optional[float] = None, baseline_func: Optional[Callable[[Sequence[float]], float]] = None, pertubation_func: Optional[Callable[[], Any]] = None, nnp_initial_value: Optional[Any] = None, stp_initial_value: Optional[Any] = None, network_opt: Optional[Any] = None, structure_opt: Optional[Any] = None, prethermal_opt: Optional[Any] = None, prethermal_preset: Optional[Sequence[int]] = None, stp_regularization: Optional[Callable[[Any, Any], Any]] = None, nnp_regularization: Optional[Callable[[Any, Any], Any]] = None) Tuple[Any, Any, Sequence[Any]] [source]#
DQAS framework entrypoint
- Parameters
kernel_func β function with input of data instance, circuit parameters theta and structural paramter k, return tuple of objective value and gradient with respect to theta
g β data generator as dataset
op_pool β list of operations as primitive operator pool
p β the default layer number of the circuit ansatz
p_nnp β shape of circuit parameter pool, in general p_stp*l, where l is the max number of circuit parameters for op in the operator pool
p_stp β the same as p in the most times
batch β batch size of one epoch
prethermal β prethermal update times
epochs β training epochs
parallel_num β parallel thread number, 0 to disable multiprocessing model by default
verbose β set verbose log to print
vebose_func β function to output verbose information
history_func β function return intermiediate result for final history list
prob_clip β cutoff probability to avoid peak distribution
baseline_func β function accepting list of objective values and return the baseline value used in the next round
pertubation_func β return noise with the same shape as circuit parameter pool
nnp_initial_value β initial values for circuit parameter pool
stp_initial_value β initial values for probabilistic model parameters
network_opt β optimizer for circuit parameters theta
structure_opt β optimizer for model parameters alpha
prethermal_opt β optimizer for circuit parameters in prethermal stage
prethermal_preset β fixed structural parameters for prethermal training
stp_regularization β regularization function for model parameters alpha
nnp_regularization β regularization function for circuit parameters theta
- Returns
- tensorcircuit.applications.dqas.DQAS_search_pmb(kernel_func: Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]], prob_model: Any, *, sample_func: Optional[Callable[[Any, int], Tuple[List[Any], List[List[Any]]]]] = None, g: Optional[Iterator[Any]] = None, op_pool: Optional[Sequence[Any]] = None, p: Optional[int] = None, batch: int = 300, prethermal: int = 0, epochs: int = 100, parallel_num: int = 0, verbose: bool = False, verbose_func: Optional[Callable[[], None]] = None, history_func: Optional[Callable[[], Any]] = None, baseline_func: Optional[Callable[[Sequence[float]], float]] = None, pertubation_func: Optional[Callable[[], Any]] = None, nnp_initial_value: Optional[Any] = None, stp_regularization: Optional[Callable[[Any, Any], Any]] = None, network_opt: Optional[Any] = None, structure_opt: Optional[Any] = None, prethermal_opt: Optional[Any] = None, loss_func: Optional[Callable[[Any], Any]] = None, loss_derivative_func: Optional[Callable[[Any], Any]] = None, validate_period: int = 0, validate_batch: int = 1, validate_func: Optional[Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]]] = None, vg: Optional[Iterator[Any]] = None) Tuple[Any, Any, Sequence[Any]] [source]#
The probabilistic model based DQAS, can use extensively for DQAS case for
NMF
probabilistic model.- Parameters
kernel_func β vag func, return loss and nabla lnp
prob_model β keras model
sample_func β sample func of logic with keras model input
g β input data pipeline generator
op_pool β operation pool
p β depth for DQAS
batch β
prethermal β
epochs β
parallel_num β parallel kernels
verbose β
verbose_func β
history_func β
baseline_func β
pertubation_func β
nnp_initial_value β
stp_regularization β
network_opt β
structure_opt β
prethermal_opt β
loss_func β final loss function in terms of average of sub loss for each circuit
loss_derivative_func β derivative function for
loss_func
- Returns
- tensorcircuit.applications.dqas.evaluate_everyone(vag_func: Any, gdata: Iterator[Any], nnp: Any, presets: Sequence[Sequence[List[int]]], batch: int = 1) Sequence[Tuple[Any, Any]] [source]#
- tensorcircuit.applications.dqas.get_var(name: str) Any [source]#
Call in customized functions and grab variables within DQAS framework function by var name str.
- Parameters
name (str) β The DQAS framework function
- Returns
Variables within the DQAS framework
- Return type
Any
- tensorcircuit.applications.dqas.get_weights(nnp: Any, stp: Optional[Any] = None, preset: Optional[Sequence[int]] = None) Any [source]#
This function works only when nnp has the same shape as stp, i.e. one parameter for each op.
- Parameters
nnp β
stp β
preset β
- Returns
- tensorcircuit.applications.dqas.micro_sample(prob_model: Any, batch_size: int, repetitions: Optional[List[int]] = None) Tuple[List[Any], List[List[Any]]] [source]#
- tensorcircuit.applications.dqas.parallel_kernel(prob: Any, gdata: Any, nnp: Any, kernel_func: Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]]) Tuple[Any, Any, Any] [source]#
The kernel for multiprocess to run parallel in DQAS function/
- Parameters
prob β
gdata β
nnp β
kernel_func β
- Returns
- tensorcircuit.applications.dqas.parallel_qaoa_train(preset: Sequence[int], g: Any, vag_func: Optional[Any] = None, opt: Optional[Any] = None, epochs: int = 60, tries: int = 16, batch: int = 1, cores: int = 8, loc: float = 0.0, scale: float = 1.0, nnp_shape: Optional[Sequence[int]] = None, search_func: Optional[Callable[[...], Any]] = None, kws: Optional[Dict[Any, Any]] = None) Sequence[Any] [source]#
parallel variational parameter training and search to avoid local minimum not limited to qaoa setup as the function name indicates, as long as you provided suitable vag_func
- Parameters
preset β
g β data input generator for vag_func
vag_func β vag_kernel
opt β
epochs β
tries β number of tries
batch β for optimization problem the input is in general fixed so batch is often 1
cores β number of parallel jobs
loc β mean value of normal distribution for nnp
scale β std deviation of normal distribution for nnp
- Returns
- tensorcircuit.applications.dqas.qaoa_simple_train(preset: Sequence[int], graph: Union[Sequence[Any], Iterator[Any]], vag_func: Optional[Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]]] = None, epochs: int = 60, batch: int = 1, nnp_shape: Optional[Any] = None, nnp_initial_value: Optional[Any] = None, opt: Optional[Any] = None, search_func: Optional[Callable[[...], Any]] = None, kws: Optional[Dict[Any, Any]] = None) Tuple[Any, float] [source]#
- tensorcircuit.applications.dqas.van_regularization(prob_model: Any, nnp: Optional[Any] = None, lbd_w: float = 0.01, lbd_b: float = 0.01) Any [source]#
- tensorcircuit.applications.dqas.van_sample(prob_model: Any, batch_size: int) Tuple[List[Any], List[List[Any]]] [source]#