mindquantum.core.parameterresolver.PRGenerator

View Source On Gitee
class mindquantum.core.parameterresolver.PRGenerator(name='p', prefix: str = '', suffix: str = '', dtype=None)[source]

Generate parameters one by one.

Parameters
  • name (str) – The main name of parameters. Default: 'p'.

  • prefix (str) – The prefix of parameters. Default: ''.

  • suffix (str) – The suffix of parameters. Default: ''.

  • dtype (mindquantum.dtype) – the data type of this parameter resolver. If None, dtype would be mindquantum.float64. Default: None.

Examples

>>> from mindquantum.core.parameterresolver import PRGenerator
>>> pr_gen = PRGenerator()
>>> print(pr_gen.new())
p0
>>> print(pr_gen.new(suffix='a'))
p1_a
>>> pr_gen.reset()
>>> print(pr_gen.new())
p0
>>> pr_gen.size()
1
new(prefix: str = '', suffix: str = '')[source]

Generate a new parameter.

Parameters
  • prefix (str) – The extra prefix when generate this new parameter. Default: ''.

  • suffix (str) – The extra suffix when generate this new parameter. Default: ''.

Examples

>>> from mindquantum.core.parameterresolver import PRGenerator
>>> pr_gen = PRGenerator(prefix='l')
>>> print(pr_gen.new(suffix='a'))
l_p1_a
reset()[source]

Reset the pr generator to initialize state.

size()[source]

Get the total size of parameters that generated.