Circuit Ansatz¶
One might wish to provide a completely custom circuit, and use it as an InQuanto
ansatz (e.g. in order to use it in InQuanto Algorithms). This is possible by simply passing
a pytket Circuit object to a
CircuitAnsatz
constructor.
For example, for minimal basis H2 , one could recover the FCI energy with the following custom circuit:
from pytket import circuit
from sympy import Symbol
from math import pi
circ = circuit.Circuit(4)
circ.X(0)
circ.X(1)
circ.CX(0, 1)
circ.CX(0, 2)
circ.CX(0, 3)
circ.V(0)
# Add custom block, of redefined Rz
theta = Symbol('\theta')
subcirc = circuit.Circuit(1)
subcirc.Rz(theta+pi, 0)
R = circuit.CustomGateDef.define("R", subcirc, [theta])
theta_index = circuit.fresh_symbol(r't_0')
circ.add_custom_gate(R, [theta_index], [0])
circ.Vdg(0)
circ.CX(0, 3)
circ.CX(0, 2)
circ.CX(0, 1)
circ.V(0); circ.V(1); circ.V(2); circ.V(3)
circ.S(0); circ.S(1); circ.S(2); circ.S(3)
circ.H(0); circ.H(1); circ.H(2); circ.H(3)
circ.S(0); circ.S(1); circ.S(2); circ.S(3)
from inquanto.ansatzes import CircuitAnsatz
my_ansatz = CircuitAnsatz(circ)