qiboml.models#
Submodules#
qiboml.models.encoding#
- class qiboml.models.encoding.QuantumEncoding(nqubits: int, qubits: Optional[tuple[int]] = None, _circuit: Circuit = None)[source]#
Bases:
ABC
Abstract Encoder class.
- Parameters:
- _circuit: Circuit = None#
- property circuit: Circuit#
Internal initialized circuit.
- property differentiable: bool#
Whether the encoder is differentiable. If
True
the gradient w.r.t. the inputs is calculated, otherwise it is automatically set to zero.
- _abc_impl = <_abc._abc_data object>#
- class qiboml.models.encoding.PhaseEncoding(nqubits: int, qubits: Optional[tuple[int]] = None, _circuit: Circuit = None)[source]#
Bases:
QuantumEncoding
- _set_phases(x: ndarray[Any, dtype[_ScalarType_co]])[source]#
Helper method to set the phases of the rotations of the internal circuit.
- Parameters:
x (ndarray) – the input rotation angles.
- __call__(x: ndarray[Any, dtype[_ScalarType_co]]) Circuit [source]#
Construct the circuit encoding the
x
data in the rotation angles of someRY
gates.- Parameters:
x (ndarray) – the input real data to encode in rotation angles.
- Returns:
the constructed
qibo.Circuit
.- Return type:
(Circuit)
- _abc_impl = <_abc._abc_data object>#
- _circuit: Circuit = None#
- property circuit: Circuit#
Internal initialized circuit.
- class qiboml.models.encoding.BinaryEncoding(nqubits: int, qubits: Optional[tuple[int]] = None, _circuit: Circuit = None)[source]#
Bases:
QuantumEncoding
- __call__(x: ndarray[Any, dtype[_ScalarType_co]]) Circuit [source]#
Construct the circuit encoding the
x
binary data in someRX
rotation gates with angles either \(\pi\) (for ones) or 0 (for zeros).- Parameters:
x (ndarray) – the input binary data.
- Returns:
the constructed
qibo.Circuit
.- Return type:
(Circuit)
- property differentiable: bool#
Whether the encoder is differentiable. If
True
the gradient w.r.t. the inputs is calculated, otherwise it is automatically set to zero.
- _abc_impl = <_abc._abc_data object>#
- _circuit: Circuit = None#
- property circuit: Circuit#
Internal initialized circuit.
qiboml.models.ansatze#
qiboml.models.decoding#
- class qiboml.models.decoding.QuantumDecoding(nqubits: int, qubits: tuple[int] = None, nshots: int = None, backend: Backend = None, _circuit: Circuit = None)[source]#
Bases:
object
Abstract decoder class.
- Parameters:
nqubits (int) – total number of qubits.
qubits (tuple[int], optional) – set of qubits it acts on, by default
range(nqubits)
.nshots (int, optional) – number of shots used for circuit execution and sampling.
backend (Backend, optional) – backend used for computation, by default the globally-set backend is used.
- backend: Backend = None#
- _circuit: Circuit = None#
- __call__(x: Circuit) Union[CircuitResult, QuantumState, MeasurementOutcomes] [source]#
Combine the input circuir with the internal one and execute them with the internal backend.
- Parameters:
x (Circuit) – input circuit.
- Returns:
the execution
qibo.result
object.- Return type:
(CircuitResult | QuantumState | MeasurementOutcomes)
- property circuit: Circuit#
A copy of the internal circuit.
- Returns:
a copy of the internal circuit.
- Return type:
(Circuit)
- set_backend(backend: Backend)[source]#
Set the internal backend.
- Parameters:
backend (Backend) – backend to be set.
- property output_shape#
The shape of the decoded outputs.
- class qiboml.models.decoding.Probabilities(nqubits: int, qubits: tuple[int] = None, nshots: int = None, backend: Backend = None, _circuit: Circuit = None)[source]#
Bases:
QuantumDecoding
The probabilities decoder.
- __call__(x: Circuit) ndarray[Any, dtype[_ScalarType_co]] [source]#
Computes the final state probabilities.
- Parameters:
x (Circuit) – input circuit.
- Returns:
the final probabilities.
- Return type:
(ndarray)
- property analytic: bool#
Whether the decoder is analytic, i.e. the gradient is ananlytically computable, or not (e.g. if sampling is involved).
- Returns:
True
ifnshots
isNone
,False
otherwise.- Return type:
(bool)
- _circuit: Circuit = None#
- backend: Backend = None#
- property circuit: Circuit#
A copy of the internal circuit.
- Returns:
a copy of the internal circuit.
- Return type:
(Circuit)
- set_backend(backend: Backend)#
Set the internal backend.
- Parameters:
backend (Backend) – backend to be set.
- class qiboml.models.decoding.Expectation(nqubits: int, qubits: tuple[int] = None, nshots: int = None, backend: Backend = None, _circuit: Circuit = None, observable: Union[ndarray[Any, dtype[_ScalarType_co]], Hamiltonian] = None)[source]#
Bases:
QuantumDecoding
The expectation value decoder.
- Parameters:
observable (Hamiltonian | ndarray) – the observable to calculate the expectation value of,
by default \(Z_0\otimes Z_1\otimes ... \otimes Z_n\) is used.
- __call__(x: Circuit) ndarray[Any, dtype[_ScalarType_co]] [source]#
Execute the input circuit and calculate the expectation value of the internal observable on the final state
- Parameters:
x (Circuit) – input Circuit.
- Returns:
the calculated expectation value.
- Return type:
(ndarray)
- set_backend(backend: Backend)[source]#
Set the internal and observable’s backends.
- Parameters:
backend (Backend) – backend to be set.
- _circuit: Circuit = None#
- property analytic: bool#
Whether the decoder is analytic, i.e. the gradient is ananlytically computable, or not (e.g. if sampling is involved).
- Returns:
True
ifnshots
isNone
,False
otherwise.- Return type:
(bool)
- backend: Backend = None#
- property circuit: Circuit#
A copy of the internal circuit.
- Returns:
a copy of the internal circuit.
- Return type:
(Circuit)
- class qiboml.models.decoding.State(nqubits: int, qubits: tuple[int] = None, nshots: int = None, backend: Backend = None, _circuit: Circuit = None)[source]#
Bases:
QuantumDecoding
The state decoder.
- __call__(x: Circuit) ndarray[Any, dtype[_ScalarType_co]] [source]#
Compute the final state of the input circuit and separates it in its real and imaginary parts stacked on top of each other.
- Parameters:
x (Circuit) – input Circuit.
- Returns:
the final state.
- Return type:
(ndarray)
- property analytic: bool#
Whether the decoder is analytic, i.e. the gradient is ananlytically computable, or not (e.g. if sampling is involved).
- Returns:
True
ifnshots
isNone
,False
otherwise.- Return type:
(bool)
- _circuit: Circuit = None#
- backend: Backend = None#
- property circuit: Circuit#
A copy of the internal circuit.
- Returns:
a copy of the internal circuit.
- Return type:
(Circuit)
- set_backend(backend: Backend)#
Set the internal backend.
- Parameters:
backend (Backend) – backend to be set.
- class qiboml.models.decoding.Samples(nqubits: int, qubits: tuple[int] = None, nshots: int = None, backend: Backend = None, _circuit: Circuit = None)[source]#
Bases:
QuantumDecoding
The samples decoder.
- __call__(x: Circuit) ndarray[Any, dtype[_ScalarType_co]] [source]#
Sample the final state of the circuit.
- Parameters:
x (Circuit) – input Circuit.
- Returns:
the generated samples.
- Return type:
(ndarray)
- property analytic: bool#
Whether the decoder is analytic, i.e. the gradient is ananlytically computable, or not (e.g. if sampling is involved).
- Returns:
True
ifnshots
isNone
,False
otherwise.- Return type:
(bool)
- _circuit: Circuit = None#
- backend: Backend = None#
- property circuit: Circuit#
A copy of the internal circuit.
- Returns:
a copy of the internal circuit.
- Return type:
(Circuit)
- set_backend(backend: Backend)#
Set the internal backend.
- Parameters:
backend (Backend) – backend to be set.