qfnn.qf_net.utils module¶
- class qfnn.qf_net.utils.BinarizeF(*args, **kwargs)¶
Bases:
torch.autograd.function.Function
>0: 1 <0:-1
- static backward(cxt, grad_output)¶
Defines a formula for differentiating the operation.
This function is to be overridden by all subclasses.
It must accept a context
ctx
as the first argument, followed by as many outputs as theforward()
returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs toforward()
. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.The context can be used to retrieve tensors saved during the forward pass. It also has an attribute
ctx.needs_input_grad
as a tuple of booleans representing whether each input needs gradient. E.g.,backward()
will havectx.needs_input_grad[0] = True
if the first input toforward()
needs gradient computated w.r.t. the output.
- static forward(cxt, input)¶
Performs the operation.
This function is to be overridden by all subclasses.
It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).
The context can be used to store arbitrary data that can be then retrieved during the backward pass.
- class qfnn.qf_net.utils.ClipF(*args, **kwargs)¶
Bases:
torch.autograd.function.Function
- static backward(ctx, grad_output)¶
Defines a formula for differentiating the operation.
This function is to be overridden by all subclasses.
It must accept a context
ctx
as the first argument, followed by as many outputs as theforward()
returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs toforward()
. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.The context can be used to retrieve tensors saved during the forward pass. It also has an attribute
ctx.needs_input_grad
as a tuple of booleans representing whether each input needs gradient. E.g.,backward()
will havectx.needs_input_grad[0] = True
if the first input toforward()
needs gradient computated w.r.t. the output.
- static forward(ctx, input)¶
Performs the operation.
This function is to be overridden by all subclasses.
It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).
The context can be used to store arbitrary data that can be then retrieved during the backward pass.
- class qfnn.qf_net.utils.Prob2amp¶
Bases:
object
- qfnn.qf_net.utils.amp2prop(state)¶
- qfnn.qf_net.utils.binarize()¶
- qfnn.qf_net.utils.clipfunc()¶
- qfnn.qf_net.utils.qf_sum(n_qubits)¶
- qfnn.qf_net.utils.save_checkpoint(state, is_best, save_path, filename)¶
- qfnn.qf_net.utils.set_value(mm, col, row, val)¶
- qfnn.qf_net.utils.tensor_sqrt(x)¶
- qfnn.qf_net.utils.tensor_squire(x)¶