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:
clone()

Performs shallow copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

copy()

Performs deep copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

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:
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:
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.

generate_report()

Returns a dict with data describing state object.

Return type:

dict

abstract get_circuit(symbol_map=None, compiler_pass=None)

Constructs a single state circuit.

Parameters:
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:
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:
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:
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.

property n_qubits: int

Returns the number of qubits.

property n_symbols: int

Returns the number of free symbols in the object.

reference_qubit_state()

Create a symbolic QubitState representation of the reference state.

Returns:

QubitState – Reference state as a QubitState.

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.

property state_symbols: SymbolSet

Returns the ordered parameter symbols this state uses.

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 using ignore_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 applied

  • ignore_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 a QubitState.

class CircuitAnsatz(circuit, reference=None)

Bases: GeneralAnsatz

An ansatz that stores a single symbolic circuit.

Parameters:
clone()

Performs shallow copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

copy()

Performs deep copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

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:
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:
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.

generate_report()

Returns a dict with data describing state object.

Return type:

dict

get_circuit(symbol_map=None, compiler_pass=None)

Constructs a single state circuit.

Parameters:
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:
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:
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:
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.

property n_qubits: int

Returns the number of qubits.

property n_symbols: int

Returns the number of free symbols in the object.

reference_qubit_state()

Create a symbolic QubitState representation of the reference state.

Returns:

QubitState – Reference state as a QubitState.

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.

property state_symbols: SymbolSet

Returns the ordered parameter symbols this state uses.

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:

CircuitAnsatzself, 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 using ignore_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 applied

  • ignore_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 a QubitState.

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 of CircuitAnsatz A, B, the composed circuit of ComposedAnsatz(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:
clone()

Performs shallow copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

copy()

Performs deep copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

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:
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:
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.

generate_report()

Returns a dict with data describing state object.

Return type:

dict

get_circuit(symbol_map=None, compiler_pass=None)

Constructs a single state circuit.

Parameters:
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:
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:
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:
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.

property n_qubits: int

Returns the number of qubits.

property n_symbols: int

Returns the number of free symbols in the object.

reference_qubit_state()

Create a symbolic QubitState representation of the reference state.

Returns:

QubitState – Reference state as a QubitState.

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.

property state_symbols: SymbolSet

Returns the ordered parameter symbols this state uses.

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:

CircuitAnsatzself, 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 using ignore_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 applied

  • ignore_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 a QubitState.

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:

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
clone()

Performs shallow copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

copy()

Performs deep copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

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:
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:
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.

generate_report()

Returns a dict with data describing state object.

Return type:

dict

get_circuit(symbol_map=None, compiler_pass=None)

Constructs a single state circuit.

Parameters:
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:
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:
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:
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.

property n_qubits: int

Returns the number of qubits.

property n_symbols: int

Returns the number of free symbols in the object.

reference_qubit_state()

Create a symbolic QubitState representation of the reference state.

Returns:

QubitState – Reference state as a QubitState.

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.

property state_symbols: SymbolSet

Returns the ordered parameter symbols this state uses.

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:

TrotterAnsatzself, 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 using ignore_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 applied

  • ignore_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 a QubitState.

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 an int, an empty initializer circuit is created with initializer number of qubits.

  • If initializer is a list of qubit-s, an empty initializer circuit is created with the qubits.

  • If initializer is a list of 0 or 1-s, an initializer circuit is created and X gate is added for

    indices where the initializer[index] == 1.

  • If initializer is a QubitSpace, an empty initializer circuit is created with

    qubits in the QubitSpace.

  • If initializer is a non-symbolic QubitState, an initializer circuit is created

    that represents the initializer state.

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 to taperer. Tapering behavior can be modified by passing tapering_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 to None (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.

clone()

Performs shallow copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

copy()

Performs deep copy of the object.

Return type:

TypeVar(SYMBOLICTYPE, bound= Symbolic)

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:
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:
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.

generate_report()

Returns a dict with data describing state object.

Return type:

dict

get_circuit(symbol_map=None, compiler_pass=None)

Constructs a single state circuit.

Parameters:
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:
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: