tensorcircuit.applications.dqas¶

Modules for DQAS framework

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: Callable[[Any, int], Tuple[List[Any], List[List[Any]]]] | None = None, g: Iterator[Any] | None = None, op_pool: Sequence[Any] | None = None, p: int | None = None, batch: int = 300, prethermal: int = 0, epochs: int = 100, parallel_num: int = 0, verbose: bool = False, verbose_func: Callable[[], None] | None = None, history_func: Callable[[], Any] | None = None, baseline_func: Callable[[Sequence[float]], float] | None = None, pertubation_func: Callable[[], Any] | None = None, nnp_initial_value: Any | None = None, stp_regularization: Callable[[Any, Any], Any] | None = None, network_opt: Any | None = None, structure_opt: Any | None = None, prethermal_opt: Any | None = None, loss_func: Callable[[Any], Any] | None = None, loss_derivative_func: Callable[[Any], Any] | None = None, validate_period: int = 0, validate_batch: int = 1, validate_func: Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]] | None = None, vg: Iterator[Any] | None = 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_op_pool() Sequence[Any][source]¶
tensorcircuit.applications.dqas.get_preset(stp: 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: Any | None = None, preset: Sequence[int] | None = 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.get_weights_v2(nnp: Any, preset: Sequence[int]) Any[source]¶
tensorcircuit.applications.dqas.history_loss() Any[source]¶
tensorcircuit.applications.dqas.micro_sample(prob_model: Any, batch_size: int, repetitions: List[int] | None = 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: Any | None = None, opt: Any | None = None, epochs: int = 60, tries: int = 16, batch: int = 1, cores: int = 8, loc: float = 0.0, scale: float = 1.0, nnp_shape: Sequence[int] | None = None, search_func: Callable[[...], Any] | None = None, kws: Dict[Any, Any] | None = 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.preset_byprob(prob: Any) Sequence[int][source]¶
tensorcircuit.applications.dqas.qaoa_simple_train(preset: Sequence[int], graph: Sequence[Any] | Iterator[Any], vag_func: Callable[[Any, Any, Sequence[int]], Tuple[Any, Any]] | None = None, epochs: int = 60, batch: int = 1, nnp_shape: Any | None = None, nnp_initial_value: Any | None = None, opt: Any | None = None, search_func: Callable[[...], Any] | None = None, kws: Dict[Any, Any] | None = None) Tuple[Any, float][source]¶
tensorcircuit.applications.dqas.repr_op(element: Any) str[source]¶
tensorcircuit.applications.dqas.set_op_pool(l: Sequence[Any]) None[source]¶
tensorcircuit.applications.dqas.single_generator(g: Any) Iterator[Any][source]¶
tensorcircuit.applications.dqas.van_regularization(prob_model: Any, nnp: Any | None = 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]¶
tensorcircuit.applications.dqas.verbose_output(max_prob: bool = True, weight: bool = True) None[source]¶

Doesn’t support prob model DQAS search.

Parameters:
  • max_prob

  • weight

Returns:

tensorcircuit.applications.dqas.void_generator() Iterator[Any][source]¶