inquanto.ansatzes
Basic ansatzes
- class GeneralAnsatz(reference, *args, **kwargs)
Bases:
Symbolic
,Representable
Base class for a quantum state that can be represented with a single circuit.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – A reference state circuit or any valid initializer forreference_circuit_builder()
.args (
Any
)kwargs (
Any
)
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
BasePass
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- abstract free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- abstract get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- abstract symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) –self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class CircuitAnsatz(circuit, reference=None)
Bases:
GeneralAnsatz
An ansatz that stores a single symbolic circuit.
- Parameters:
circuit (
Circuit
) – A symbolic circuit.reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
,None
], default:None
) – An optional reference state circuit or any valid initializer forreference_circuit_builder()
.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
BasePass
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
CircuitAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class ComposedAnsatz(*ansatzes, reference=None)
Bases:
CircuitAnsatz
Composes circuit ansatzes into one circuit ansatz.
Note
The composed circuit is built by applying the arguments of the
ComposedAnsatz
constructor in reverse order. i.e. for two instances ofCircuitAnsatz
A, B, the composed circuit ofComposedAnsatz(A, B)
represents the state AB \(|0\rangle\), hence B is applied first.Examples
>>> A = CircuitAnsatz(Circuit(1).Y(0)) >>> B = CircuitAnsatz(Circuit(1).Z(0), [1]) >>> ComposedAnsatz(A, B).get_circuit() [X q[0]; Z q[0]; Y q[0]; ] >>> C = CircuitAnsatz(Circuit(1).Y(0)) >>> D = CircuitAnsatz(Circuit(1).Z(0)) >>> ComposedAnsatz(C, D, reference = [1]).get_circuit() [X q[0]; Z q[0]; Y q[0]; ]
- Parameters:
*ansatzes (
GeneralAnsatz
) – Sequence of circuit ansatzes that will be appended together.reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
,None
], default:None
) – An optional reference state circuit or any valid initializer forreference_circuit_builder()
.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
BasePass
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
CircuitAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class TrotterAnsatz(exponents, reference=None)
Bases:
GeneralAnsatz
Ansatz representing a state built from a product of Pauli-exponentials.
This is at the core of the UCC family of
ansatzes
in InQuanto.Note: This class requires numerical operators within the input
QubitOperatorList
.- Parameters:
exponents (
QubitOperatorList
) – Contains exponent and symbol data.reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
,None
], default:None
) – An optional reference state circuit or any valid initializer forreference_circuit_builder()
.
Examples
>>> from inquanto.states import QubitState >>> exponents = QubitOperatorList.from_string("a [(1j, Y0 X2)], b [(1j, Y1 X3)]") >>> ref = QubitState([1, 1, 0, 0]) >>> ansatz = TrotterAnsatz(exponents, reference=ref) >>> ansatz.free_symbols_ordered() # returns an lexicographically ordered set of symbols SymbolSet([a, b]) >>> ansatz.free_symbols() == {Symbol("a"), Symbol("b")} # returns a set of symbols True >>> ansatz.subs("new_{}").free_symbols() == {Symbol("new_a"), Symbol("new_b")} # new instance True >>> ansatz2 = ansatz.symbol_substitution("new_{}") # in-place substitution >>> ansatz2 is ansatz True >>> ansatz.free_symbols() == {Symbol("new_a"), Symbol("new_b")} True
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- reference_circuit_builder(initializer)
Building a non-symbolic reference circuit.
- Parameters:
initializer (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
,None
]) –- A non-symbolic initializer circuit or an object that can be converted to one.
If
initializer
is anint
, an empty initializer circuit is created withinitializer
number of qubits.If
initializer
is alist
of qubit-s, an empty initializer circuit is created with the qubits.- If
initializer
is alist
of 0 or 1-s, an initializer circuit is created andX
gate is added for indices where the
initializer[index] == 1
.
- If
- If
initializer
is aQubitSpace
, an empty initializer circuit is created with qubits in the
QubitSpace
.
- If
- If
initializer
is a non-symbolicQubitState
, an initializer circuit is created that represents the initializer state.
- If
- Returns:
Optional
[Circuit
] – A non-symbolic reference circuit.
Fermion Space ansatzes
- class FermionSpaceStateExp(fermion_operator_exponents, fock_state, qubit_mapping=QubitMappingJordanWigner(), qubits=None, taperer=None, tapering_exponent_check_behaviour='except', *args, **kwargs)
Bases:
TrotterAnsatz
Fermion operator exponentiation (e.g. for UCC). Also initializes state trotterization.
Qubit tapering can optionally be performed. To enable qubit tapering, pass a
TapererZ2
object totaperer
. Tapering behavior can be modified by passingtapering_exponent_check_behaviour
as specified below.- Parameters:
fermion_operator_exponents (
FermionOperatorList
) – Excitation operators (anti-hermitian for UCC).fock_state (
FermionState
) – Spin orbital occupations.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.qubits (
Optional
[List
[Qubit
]], default:None
) – The qubit register used to represent the ansatz state. If no register is provided, a minimal register consisting of qubits indexed from 0 to N is built, where N is the number of spin-orbitals in the reference state provided. Note that this may include qubits corresponding to spin-orbitals which the excitations do not act on.taperer (
TapererZ2
, default:None
) – The taperer object used to control how the ansatz is tapered. Set toNone
(default) to skip.tapering_exponent_check_behaviour (
str
, default:"except"
) –Controls treatment of exponents which don’t commute with the Z2 symmetry operators. Options are:
"except"
: Tests each exponent and throws an exception if any exponent does not commute with the symmetry operators."skip"
: Skips exponent testing entirely. This may be dangerous (and is untested) but will be faster when exponents are known to be safe."discard"
: Tests each exponent and discards any that don’t commute with the Z2 symmetry operators. This should only discard excitations which don’t contribute to the ground state, but may be unsafe.
*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzUCCSD(fermion_space, fermion_state, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
Unitary coupled cluster with singles and doubles excitations (UCCSD).
Builds ansatz for a given
fermion_space
andfermion_state
.- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzUCCD(fermion_space, fermion_state, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
Unitary coupled cluster with doubles excitations, no singles (UCCD).
Builds ansatz for a given
fermion_space
andfermion_state
.- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceStateExpChemicallyAware(fermion_operator_exponents, fermion_state)
Bases:
GeneralAnsatz
Efficient fermion operator exponentiation (e.g. for UCC). Also initialises state trotterization.
Synthesizes molecular orbital to molecular orbital double excitations uniquely. Changes trotter order of excitations to synthesize circuit with fewer two qubit gates compared to
FermionSpaceStateExp
. Circuit is synthesized in Jordan-Wigner encoding.- Parameters:
fermion_operator_exponents (
FermionOperatorList
) – Contains exponents and symbols. Assumes input exponents are ordered as single exponents first, followed by double exponents.fermion_state (
FermionState
) – Initial fermionic reference state.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
BasePass
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
FermionSpaceStateExpChemicallyAware
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class FermionSpaceAnsatzChemicallyAwareUCCSD(fermion_space, fermion_state, *args, **kwargs)
Bases:
FermionSpaceStateExpChemicallyAware
Chemically aware unitary coupled cluster with singles and doubles excitations (UCCSD).
Described in https://doi.org/10.1063/5.0144680.
Builds ansatz for a given
fermion_space
andfermion_state
. Circuit is synthesized in Jordan-Wigner encoding.- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
BasePass
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
FermionSpaceStateExpChemicallyAware
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class FermionSpaceAnsatzkUpCCGD(fermion_space, fermion_state, k_input, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
k-UpCCGD Ansatz.
Ansatz consisting of k factors of variationally independent unitary coupled cluster operators with generalized spin-paired doubles excitations, no singles (k-UpCCGD).
Here, generalized means occupied and virtual orbital subspaces are undistinguished, hence occupied-occupied and virtual-virtual excitations are included. See https://arxiv.org/abs/1810.02327 for more details.
- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.k_input (
int
) – Value of k in k-UpCC; results in k cluster operators.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzkUpCCGSD(fermion_space, fermion_state, k_input, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
k-UpCCGSD ansatz.
Ansatz consisting of k factors of variationally independent unitary coupled cluster operators with fully generalized singles and generalized spin-paired doubles excitations (k-UpCCGSD).
Here, generalized means occupied and virtual orbital subspaces are undistinguished, hence occupied-occupied and virtual-virtual excitations are included. See https://arxiv.org/abs/1810.02327 for more details.
- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.k_input (
int
) – Value of k in k-UpCC; results in k cluster operators.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzkUpCCGSDSinglet(fermion_space, fermion_state, k_input, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
k-UpCCGSDSinglet ansatz.
Ansatz consisting of k factors of variationally independent unitary coupled cluster operators with fully generalized singles and generalized spin paired doubles excitations.
Here, generalized means occupied and virtual orbital subspaces are undistinguished, hence occupied-occupied and virtual-virtual excitations are included. See https://arxiv.org/abs/1810.02327 for more details.
Adapted to singlets, so alpha-alpha and beta-beta single excitations between a given pair of spatial orbitals have the same parameter.
- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.k_input (
int
) – Value of k in k-UpCC; results in k cluster operators.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzUCCGD(fermion_space, fermion_state, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
Unitary coupled cluster with fully generalized doubles excitations, no singles (UCCGD).
Here, generalized means occupied and virtual orbital subspaces are undistinguished, hence occupied-occupied and virtual-virtual excitations are included. See https://arxiv.org/abs/1810.02327 for more details.
- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzUCCGSD(fermion_space, fermion_state, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
Unitary coupled cluster with fully generalized singles and doubles excitations (UCCGSD).
Here, generalized means occupied and virtual orbital subspaces are undistinguished, hence occupied-occupied and virtual-virtual excitations are included. See https://arxiv.org/abs/1810.02327 for more details.
- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class FermionSpaceAnsatzUCCSDSinglet(fermion_space, fermion_state, qubit_mapping=QubitMappingJordanWigner(), *args, **kwargs)
Bases:
FermionSpaceStateExp
Unitary coupled cluster with singles and doubles excitations (UCCSD).
Builds ansatz for a given
fermion_space
andfermion state
.Adapted to singlets, so alpha-alpha and beta-beta single excitations between a given pair of spatial orbitals have the same parameter.
- Parameters:
fermion_space (
Union
[FermionSpace
,int
]) – Spin orbital indices, occupations, and spatial orbitals indices.fermion_state (
FermionState
) – Spin orbital occupations.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map fock state operators and states to qubit operators and circuits.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- property fermion_operator_exponents: FermionOperatorList
Returns the list of exponents of the exponential product included in the ansatz.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
Multi-configurational ansatzes
- class MultiConfigurationAnsatz(configurations, reference=None)
Bases:
GeneralAnsatz
Variational ansatz consisting of selected occupation configurations, using Givens rotations.
Consists of occupation configurations which have symbolic coefficients.
Follows logic of https://quantum-journal.org/papers/q-2022-06-20-742/, with in-house developed procedures to control Givens rotations.
Finds necessary controls of Givens rotation boxes using method based on hamming distances (and their qubit-wise decompositions) of all configurations relative to the first.
For single excitations (2 qubits), hamming distance = 2, the 1-body Givens rotation (G1) in Figure 12 of https://quantum-journal.org/papers/q-2022-06-20-742/ is used.
For double excitations (4 qubits), hamming distance = 4, the 2-body Givens rotation (G2) in Figure 11 of https://quantum-journal.org/papers/q-2022-06-20-742/ is used.
Excitations that are higher than doubles are achieved by nesting a controlled G1 inside a ladder of controlled-SWAPs (G1(>2)).
Note
Supports only basis configurations which have the same number of 1s in the bit string. This corresponds to configurations with the same particle number as Jordan-Wigner encoding is assumed.
- Parameters:
configurations (
List
[QubitStateString
]) – List ofQubitStateString
objects providing the basis configurations for the ansatz linear combination.reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
,None
], default:None
) – An optional reference state circuit or any valid initializer forreference_circuit_builder()
.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
MultiConfigurationAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class MultiConfigurationState(input_states)
Bases:
GeneralAnsatz
State preparation for a selected linear combination of occupation configurations with fixed coefficients.
Configuration coefficients must be real-valued.
Follows logic of https://quantum-journal.org/papers/q-2022-06-20-742/, with in-house developed procedures to control Givens rotations.
Finds necessary controls of Givens rotation boxes using method based on hamming distances (and their qubit-wise decompositions) of all configurations relative to the first.
For single excitations (2 qubits), hamming distance = 2, the 1-body Givens rotation (G1) in Figure 12 of https://quantum-journal.org/papers/q-2022-06-20-742/ is used.
For double excitations (4 qubits), hamming distance = 4, the 2-body Givens rotation (G2) in Figure 11 of https://quantum-journal.org/papers/q-2022-06-20-742/ is used.
Excitations that are higher than doubles are achieved by nesting a controlled G1 inside a ladder of controlled-SWAPs (G1(>2)).
Note
Supports only basis configurations which have the same number of 1s in the bit string. This corresponds to configurations with the same particle number as Jordan-Wigner encoding is assumed.
- Parameters:
input_states (
QubitState
) – Multi-reference qubit state input, providing basis configurations and numerical coefficients. Coefficients must be real and normalised.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[Transform
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) –self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class MultiConfigurationStateBox(input_states)
Bases:
GeneralAnsatz
State preparation for a selected linear combination of occupation configurations with fixed coefficients.
Serves as a wrapper for pytket’s
StatePreparationBox
.Converts input
QubitState
to ndarray state vector (exponentially scaling), passes this toStatePreparationBox
which prepares the state vector using multiplexed-Ry
and multiplexed-Rz
gates.See https://cqcl.github.io/tket/pytket/api/circuit.html#pytket.circuit.StatePreparationBox.
- Parameters:
input_states (
QubitState
) – Multi-referenceQubitState
input, providing basis configurations and numerical coefficients.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[Transform
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) –self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
Rotational ansatzes
- class RealGeneralizedBasisRotationAnsatz(reference)
Bases:
BaseRealBasisRotationAnsatz
Basis rotation ansatz that allows for generalized real unitary rotations.
Constructs the ansatz \(\hat{R} \ket{\Psi}\) where \(\hat{R}\) is given by the Thouless theorem: \(\hat{R} = \exp\left[ \sum_{ij}[\ln U]_{ij} a_i^\dagger a_j \right]\) and \(U\) is a single-particle basis rotation matrix (real, unitary). See https://arxiv.org/abs/1711.04789.
Note
Supports generalized rotations which may mix spin channels.
Note
Uses a Jordan-Wigner mapping for encoding rotations.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Initial reference state, \(\ket{\Psi}\) above. Can be any valid initializer forreference_circuit_builder()
.
- ansatz_parameters_from_unitary(rotation_unitary)
Converts a real unitary rotation to ansatz parameters.
Performs a QR decomposition of the rotation matrix to find ansatz parameters.
- Parameters:
rotation_unitary (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(N_{so}, N_{so})
whereN_{so}
is the of number of spin-orbitals/qubits. Assumes the spin-orbital encoding: [0a, 0b, 1a, 1b, 2a…].- Returns:
SymbolDict
– A SymbolDict of the ansatz parameters.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
DecomposeBoxes
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
BaseRealBasisRotationAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class RealRestrictedBasisRotationAnsatz(reference)
Bases:
BaseRealBasisRotationAnsatz
Basis rotation ansatz that allows for restricted-spin, real unitary rotations.
Constructs the ansatz \(\hat{R} \ket{\Psi}\) where \(\hat{R}\) is given by the Thouless theorem: \(\hat{R} = \exp\left[ \sum_{ij}[\ln U]_{ij} a_i^\dagger a_j \right]\) and \(U\) is a single-particle basis rotation matrix (real, unitary). See https://arxiv.org/abs/1711.04789.
Note
Supports rotations which act on both spin channels equivalently, and independently.
Note
Uses a Jordan-Wigner mapping for encoding rotations.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Initial reference state, \(\ket{\Psi}\) above.
- ansatz_parameters_from_unitary(rotation_unitary)
Converts a real unitary rotation to ansatz parameters.
Performs a QR decomposition of the rotation matrix to find ansatz parameters.
- Parameters:
rotation_unitary (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(n_orb, n_orb)
wheren_orb
is the of number of spatial orbitals. This rotation is applied to both spin channels.- Returns:
SymbolDict
– A SymbolDict of the ansatz parameters.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
DecomposeBoxes
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
BaseRealBasisRotationAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class RealUnrestrictedBasisRotationAnsatz(reference)
Bases:
BaseRealBasisRotationAnsatz
Basis rotation ansatz that allows for unrestricted-spin, real unitary rotations.
Constructs the ansatz \(\hat{R} \ket{\Psi}\) where \(\hat{R}\) is given by the Thouless theorem: \(\hat{R} = \exp\left[ \sum_{ij}[\ln U]_{ij} a_i^\dagger a_j \right]\) and \(U\) is a single-particle basis rotation matrix (real, unitary). See https://arxiv.org/abs/1711.04789.
Note
Supports rotations which transform each spin channel independently.
Note
Uses a Jordan-Wigner mapping for encoding rotations.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Initial reference state, \(\ket{\Psi}\) above.
- ansatz_parameters_from_unitary(rotation_unitary_a, rotation_unitary_b)
Converts a real unitary rotation to ansatz parameters.
Performs a QR decomposition of the rotation matrix to find ansatz parameters.
- Parameters:
rotation_unitary_a (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(n_orb, n_orb)
wheren_orb
is the of number of spatial orbitals. This rotation is applied to the alpha spin channel.rotation_unitary_b (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(n_orb, n_orb)
wheren_orb
is the of number of spatial orbitals. This rotation is applied to the beta spin channel. Must be the same shape asrotation_unitary_a
.
- Returns:
SymbolDict
– A SymbolDict of the ansatz parameters.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
DecomposeBoxes
– A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
BaseRealBasisRotationAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- generalized_basis_rotation_to_circuit(rotation_unitary)
Converts a real unitary basis rotation to a circuit.
Supports generalized real rotations, which may couple and mix spin channels.
Note
Uses a Jordan-Wigner mapping for encoding rotations.
- Parameters:
rotation_unitary (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(N_{so}, N_{so})
whereN_{so}
is the of number of spin-orbitals/qubits. Assumes the spin-orbital encoding: [0a, 0b, 1a, 1b, 2a…].- Returns:
A circuit representing the basis rotation matrix, the number of qubits equals to the number of spin-orbitals.
- restricted_basis_rotation_to_circuit(rotation_unitary)
Converts a real unitary basis rotation to a circuit.
Rotation is applied to both alpha and beta spin channels.
Note
Uses a Jordan-Wigner mapping for encoding rotations.
- unrestricted_basis_rotation_to_circuit(rotation_unitary_a, rotation_unitary_b)
Converts a pair of real unitary basis rotations to a circuit.
Each rotation matrix corresponds to a spin channel.
Note
Uses a Jordan-Wigner mapping for encoding rotations.
- Parameters:
rotation_unitary_a (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(n_{orb}, n_{orb})
wheren_{orb}
is the of number of spatial orbitals. This rotation is applied to the alpha spin channel.rotation_unitary_b (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(n_{orb}, n_{orb})
wheren_{orb}
is the of number of spatial orbitals. This rotation is applied to the alpha spin channel. Must be the same shape asrotation_unitary_a
.
- Returns:
A circuit representing the basis rotation matrix, the number of qubits equals to the number of spin-orbitals.
- rotate_ansatz_restricted(ansatz, rotation_unitary)
Rotate an ansatz by a real unitary basis rotation.
Rotation is applied to both alpha and beta spin channels. Uses
restricted_basis_rotation_to_circuit()
in combination withCircuitAnsatz
andComposedAnsatz
to build a new state.Note
Uses a Jordan-Wigner mapping for encoding rotations.
- Parameters:
ansatz (
GeneralAnsatz
) – Input ansatz to be rotated. Must be encoded with the Jordan-Wigner mapping.rotation_unitary (
ndarray
[Any
,dtype
[float
]]) – A real unitary matrix with shape(n_{orb}, n_{orb})
wheren_{orb}
is the of number of spatial orbitals.
- Returns:
A new ansatz with the rotation appended to the state preparation circuit.
Other ansatzes
- class HamiltonianVariationalAnsatz(fermion_state, hamiltonian_operator=FermionOperator(), qubit_mapping=QubitMappingJordanWigner(), s=1, *args, **kwargs)
Bases:
TrotterAnsatz
Hamiltonian Variational Ansatz introduced in https://arxiv.org/abs/1507.08969.
- Parameters:
fermion_state (
FermionState
) – Spin orbital occupations. If applied to molecules, this should represent a single configuration mean field state.hamiltonian_operator (
FermionOperator
, default:FermionOperator()
) – The hamiltonian operator produced by driver.qubit_mapping (
QubitMapping
, default:QubitMappingJordanWigner()
) – How to map Fock state operators and states to qubit operators and circuits.s (
int
, default:1
) – The number of terms in the multiplication; the total number of parameters will be 5*s.*args – Additional arguments offered by parent object.
**kwargs – Additional keyword arguments offered by parent object.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- property exponents: QubitOperatorList
Returns the qubit operator exponents.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property split_hamiltonian: Tuple[FermionOperator]
Split hamiltonian into diagonal and non-diagonal elements.
Hamiltonian is separated into three terms \(H_{diag}\), \(H_{hop}\), and \(H_{ex}\), each one a
FermionOperator
. These will be exponentiated to build the Hamiltonian Variational Ansatz.Diagonal terms:\(H_{diag} = \sum_p (e_p a^\dagger_p a_p) + \sum_{p,q}( h_{pqqp} a^\dagger_p a_p a^\dagger_q a_q )\)in terms of FermionOperator:\(((p,1), (p,0)) : e_p\) and \(((p,1), (q,1), (p,0), (q,0)) : h_{pqqp}\)Hopping terms:\(H_{hop} = \sum_{p,q} (e_{p,q} a^\dagger_p a_q) + \sum_{p,r,q} ( h_{prrp} a^\dagger_p a_q a^\dagger_r a_r )\)in terms of FermionOperator:\(((p,1), (q,0)) : e_p,q\) and \(((p,1), (q,1), (q,0), (r,0)) : h_{pqqp}\)Exchange terms:\(H_{ex} = \sum_{p,q,r,s} ( h_{pqrs} a^\dagger_p a^\dagger_r a_r a_s)\)in terms of FermionOperator:\((((p,1), (q,1), (r,0), (s,0)) : h_{pqrs}\)- Returns:
Diagonal, hopping, and exchange operators extracted from the Hamiltonian.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
TrotterAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- to_QubitState_direct(reverse=False)
Returns a
QubitState
object corresponding to the generated state.This proceeds through direct exponentiation of individual terms and application to the reference state. The ansatz must have been constructed with a QubitState reference.
Danger
In general, this will blow up exponentially.
- Parameters:
reverse (
bool
, default:False
) – set to True to reverse the order of term application- Returns:
QubitState
– The Ansatz state.
- class LayeredAnsatz(rotations_def, reference, n_layers=1, inter_block_entangler=True, entangler_def=None, cap_layers=True, cap_def=None)
Bases:
GeneralAnsatz
Parent class for ansatzes with layered replicas of a group of circuit primitives (such as HEA).
- Hierarchy:
Block (
CustomGateDef
): Consists of a collection of parametricpytket.circuit.OpType
operations added to a circuit.Layer (
CircBox
): Consists of a rotation block and (possibly) an entangler block. Ifinter_block_entangler=True
(default), rotation blocks between layers are separated by a block of two_qubit operations (entangler).
- Parameters:
rotations_def (
List
[CustomGateDef
]) – A list of circuit primitives asCustomGateDefs
to be placed inside a layer.reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – A reference state circuit or any valid initializer forreference_circuit_builder()
.n_layers (
int
, default:1
) – Number of layers to be added to circuit.inter_block_entangler (
bool
, default:True
) – IfTrue
add a block of two-qubit gate primitives between rotation blocks within a layer.entangler_def (
CustomGateDef
, default:None
) – Definition of the two-qubit entangler primitive.cap_layers (
bool
, default:True
) – If True end circuit by adding one extra block of rotations.cap_def (
List
[CustomGateDef
], default:None
) – A list of circuit primitives asCustomGateDefs
for the cap.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
LayeredAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.
- class HardwareEfficientAnsatz(rotation_operations, reference, n_layers, entangler_operation=OpType.CX)
Bases:
LayeredAnsatz
Hardware Efficient Ansatz as defined in https://arxiv.org/abs/1704.05018.
Consists of
n_layers
layers of circuit primitives. Each layer consists of a rotation block and an entangler block.- Parameters:
rotation_operations (
List
[OpType
]) – Define blocks of rotations asRy
,RxRy
orRxRyRz
.reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Initial state of qubit register. A reference state circuit or any valid initializer forreference_circuit_builder()
.n_layers (
int
) – Number of layers.entangler_operation (
OpType
, default:OpType.CX
) – The operation to build the entangler block. Default value is aCX
gate.
- default_pass()
Get the default compiler pass for the ansatz type.
- Returns:
A tket pass object.
- df_numeric(symbol_map=None, *, space=None, backend=None, dtype=complex, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_numeric_representation()
to generate a numeric vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_numeric_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_numeric_representation()
.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation. Passed toget_numeric_representation()
.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted. Passed toget_numeric_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- df_symbolic(symbol_map=None, *, space=None, tol=1e-10)
Returns a
pandas.DataFrame
representation of the ansatz state.Uses
get_symbolic_representation()
to generate a symbolic vector for the ansatz state, and returns a dataframe with coefficients alongside their corresponding computational basis states.Assumes lexicographical ordering of basis states.
Symbolic coefficients are simplified before being added to dataframe.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation. Passed toget_symbolic_representation()
.space (
Any
, default:None
) – Basis information to represent the object. Passed toget_symbolic_representation()
.tol (
float
, default:1e-10
) – Absolute tolerance below which terms in the ansatz will be omitted from the dataframe. If negative, no terms are discarded.
- Returns:
DataFrame
– A dataframe representing the object.
- free_symbols()
Returns the free symbols in the object.
- Returns:
Set
[Symbol
] – Unordered set of symbols.
- free_symbols_ordered()
Returns the free symbols in increasing lexicographic order as SymbolSet.
- Returns:
SymbolSet
– Ordered free symbols in object.
- get_circuit(symbol_map=None, compiler_pass=None)
Constructs a single state circuit.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the state.
- get_circuit_no_ref(symbol_map=None, compiler_pass=None)
Constructs a single state circuit without the reference state.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol mapping for substitution.compiler_pass (
BasePass
, default:None
) – Optional compiler pass for circuit compilation.
- Returns:
Circuit
– A circuit that represent the referenceless state.
- get_numeric_representation(symbol_map=None, *, space=None, backend=None, dtype=complex)
Constructs a single numeric matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.backend (
Optional
[Backend
], default:None
) – An optional backend to use to build the representation.dtype (
Union
[dtype
[Any
],None
,type
[Any
],_SupportsDType
[dtype
[Any
]],str
,tuple
[Any
,int
],tuple
[Any
,Union
[SupportsIndex
,Sequence
[SupportsIndex
]]],list
[Any
],_DTypeDict
,tuple
[Any
,Any
]], default:complex
) – Specifies what dtype the return array should be converted.
- Returns:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]] – A matrix/vector representing the object.
- get_symbolic_representation(symbol_map=None, *, space=None)
Constructs a single symbolic matrix/vector representation.
Danger
This is an exponentially exploding method!
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – A symbol substitution map before constructing the representation.space (
Any
, default:None
) – Basis information to represent the object.
- Returns:
Expr
– A symbolic expression as a representation, which is a symbolic NDArray.
- make_hashable()
Returns a hashable string representation of the ansatz object.
- Returns:
str
– Hashable string representation of ansatz.
- reference_qubit_state()
Create a symbolic
QubitState
representation of the reference state.- Returns:
QubitState
– Reference state as aQubitState
.
- reset_reference(reference)
Resetting the reference state of the ansatz in place.
Note
The number of qubits in the new reference has to match with the already existing reference state.
- Parameters:
reference (
Union
[int
,List
[Qubit
],List
[int
],QubitSpace
,QubitState
,Circuit
]) – Any reference that can be converted into a non-symbolic reference state circuit.- Returns:
Returns self with the modified reference.
- property state_circuit: Circuit
Returns the symbolic state circuit with a default compilation.
- subs(symbol_map)
Returns a new objects with symbols substituted.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
]) – A mapping for substitution of free symbols.- Returns:
TypeVar
(SYMBOLICTYPE
, bound= Symbolic) – A copy of self with symbols substituted according to the provided map.
- symbol_substitution(symbol_map=None)
Performs an in-place symbol substation in the object.
- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Dictionary or Callable mapping existing symbols to new symbols or values.
Note
While this is an in-place operation, consistency in free_symbols_ordered() is not guaranteed.
- Returns:
LayeredAnsatz
–self
, with symbols substituted.
- to_CircuitAnsatz(symbol_map=None, compiler_pass=None, ignore_default_pass=False)
Cast the ansatz as CircuitAnsatz with optional symbol substitution and compilation control.
Note
Some ansatzes have built in tket compiler passes. These can be ignored when casting to the
CircuitAnsatz
usingignore_default_pass
. This can be combined with the user defined compiler_pass for full control. If the result of self.default_pass is not ignored and a compiler_pass is defined then both sets of passes will be combined and applied.- Parameters:
symbol_map (
Union
[SymbolDict
,Dict
[Symbol
,Expr
],Dict
[Symbol
,float
],Dict
[Symbol
,Union
[float
,complex
,Expr
]],Callable
[[Symbol
],Expr
],str
,None
], default:None
) – Optional symbol substitution map.compiler_pass (
Optional
[BasePass
], default:None
) – Optional compiler pass for circuit compilation appliedignore_default_pass (
bool
, default:False
) – Prevents the ansatz self.default_pass being applied
- Returns:
CircuitAnsatz – A new
CircuitAnsatz
ansatz.
- to_QubitState()
Create a symbolic
QubitState
representation of the ansatz.- Returns:
QubitState
– Ansatz as aQubitState
.