# Results

`Braket.Result`

— Type`Result`

Abstract type representing a measurement to perform on a `Circuit`

.

See also: `Expectation`

, `Variance`

, `Sample`

, `Probability`

, `DensityMatrix`

, and `Amplitude`

.

`Braket.AdjointGradient`

— Type`AdjointGradient <: Result`

Struct which represents a gradient computation using the adjoint differentiation method on a `Circuit`

.

`Braket.AdjointGradient`

— Method```
AdjointGradient(o::Observable, targets, parameters::Vector) -> AdjointGradient
AdjointGradient(o::Observable, targets) -> AdjointGradient
```

Constructs an `AdjointGradient`

with respect to the expectation value of an observable `o`

on qubits `targets`

. The gradient will be calculated by computing partial derivatives with respect to `parameters`

. If `parameters`

is not present, is empty, or is `["all"]`

, all parameters in the circuit will be used.

`targets`

may be one of:

`AdjointGradient`

supports using `Sum`

observables. If `o`

is a `Sum`

, `targets`

should be a nested vector of target qubits, such that the `n`

-th term of `targets`

has the same length as the `n`

-th term of `o`

.

**Examples**

```
julia> α = FreeParameter(:alpha);
julia> c = Circuit([(H, 0), (H, 1), (Rx, 0, α), (Rx, 1, α)]);
julia> op = 2.0 * Braket.Observables.X() * Braket.Observables.X();
julia> c = AdjointGradient(c, op, [QubitSet(0, 1)], [α]);
```

Using a `Sum`

:

```
julia> α = FreeParameter(:alpha);
julia> c = Circuit([(H, 0), (H, 1), (Rx, 0, α), (Rx, 1, α)]);
julia> op1 = 2.0 * Braket.Observables.X() * Braket.Observables.X();
julia> op2 = -3.0 * Braket.Observables.Y() * Braket.Observables.Y();
julia> c = AdjointGradient(c, op1 + op2, [QubitSet(0, 1), QubitSet(0, 2)], [α]);
```

`Braket.AdjointGradient`

— Method`AdjointGradient(c::Circuit, o::Observable, targets, parameters) -> Circuit`

Constructs an `AdjointGradient`

computation with respect to the expectation value of an observable `o`

on qubits `targets`

, computing partial derivatives of `parameters`

, and adds it as a result to `Circuit`

`c`

.

`o`

may be any `Observable`

. `targets`

must be a `Vector`

of `QubitSet`

s (or a single `QubitSet`

, if `o`

is not a `Sum`

), each of which is the same length as the qubit count of the corresponding term in `o`

. `parameters`

can have elements which are `FreeParameter`

s or `String`

s, or `["all"]`

, in which case the gradient is computed with respect to all parameters in the circuit.

**Examples**

```
julia> c = Circuit();
julia> α = FreeParameter("alpha");
julia> c = H(c, collect(0:10));
julia> c = Rx(c, collect(0:10), α);
julia> c = AdjointGradient(c, Braket.Observables.Z(), 0, [α]);
```

`Braket.Expectation`

— Type`Expectation <: Result`

Struct which represents a expectation measurement on a `Circuit`

.

`Braket.Expectation`

— Method```
Expectation(o, targets) -> Expectation
Expectation(o) -> Expectation
```

Constructs a Expectation of an observable `o`

on qubits `targets`

.

`o`

may be one of:

- Any
`Observable`

- A
`String`

corresponding to an`Observable`

(e.g.`"x"`

`) - A
`Vector{String}`

in which each element corresponds to an`Observable`

`targets`

may be one of:

`Braket.Expectation`

— Method```
Expectation(c::Circuit, o, targets) -> Circuit
Expectation(c::Circuit, o) -> Circuit
```

Constructs a `Expectation`

of an observable `o`

on qubits `targets`

and adds it as a result to `Circuit`

`c`

.

`o`

may be one of:

- Any
`Observable`

- A
`String`

corresponding to an`Observable`

(e.g. "x") - A
`Vector{String}`

in which each element corresponds to an`Observable`

`targets`

may be one of:

- A
`QubitSet`

- A
`Vector`

of`Int`

s and/or`Qubit`

s - An
`Int`

or`Qubit`

- Absent, in which case the observable
`o`

will be applied to all qubits provided it is a single qubit observable.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:10));
julia> c = Expectation(c, Braket.Observables.Z(), 0);
julia> c = Expectation(c, Braket.Observables.X());
```

`Braket.Variance`

— Type`Variance <: Result`

Struct which represents a variance measurement on a `Circuit`

.

`Braket.Variance`

— Method```
Variance(o, targets) -> Variance
Variance(o) -> Variance
```

Constructs a Variance of an observable `o`

on qubits `targets`

.

`o`

may be one of:

- Any
`Observable`

- A
`String`

corresponding to an`Observable`

(e.g.`"x"`

`) - A
`Vector{String}`

in which each element corresponds to an`Observable`

`targets`

may be one of:

`Braket.Variance`

— Method```
Variance(c::Circuit, o, targets) -> Circuit
Variance(c::Circuit, o) -> Circuit
```

Constructs a `Variance`

of an observable `o`

on qubits `targets`

and adds it as a result to `Circuit`

`c`

.

`o`

may be one of:

- Any
`Observable`

- A
`String`

corresponding to an`Observable`

(e.g. "x") - A
`Vector{String}`

in which each element corresponds to an`Observable`

`targets`

may be one of:

- A
`QubitSet`

- A
`Vector`

of`Int`

s and/or`Qubit`

s - An
`Int`

or`Qubit`

- Absent, in which case the observable
`o`

will be applied to all qubits provided it is a single qubit observable.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:10));
julia> c = Variance(c, Braket.Observables.Z(), 0);
julia> c = Variance(c, Braket.Observables.X());
```

`Braket.Sample`

— Type`Sample <: Result`

Struct which represents a sample measurement on a `Circuit`

.

`Braket.Sample`

— Method```
Sample(o, targets) -> Sample
Sample(o) -> Sample
```

Constructs a Sample of an observable `o`

on qubits `targets`

.

`o`

may be one of:

- Any
`Observable`

- A
`String`

corresponding to an`Observable`

(e.g.`"x"`

`) - A
`Vector{String}`

in which each element corresponds to an`Observable`

`targets`

may be one of:

`Braket.Sample`

— Method```
Sample(c::Circuit, o, targets) -> Circuit
Sample(c::Circuit, o) -> Circuit
```

Constructs a `Sample`

of an observable `o`

on qubits `targets`

and adds it as a result to `Circuit`

`c`

.

`o`

may be one of:

- Any
`Observable`

- A
`String`

corresponding to an`Observable`

(e.g. "x") - A
`Vector{String}`

in which each element corresponds to an`Observable`

`targets`

may be one of:

- A
`QubitSet`

- A
`Vector`

of`Int`

s and/or`Qubit`

s - An
`Int`

or`Qubit`

- Absent, in which case the observable
`o`

will be applied to all qubits provided it is a single qubit observable.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:10));
julia> c = Sample(c, Braket.Observables.Z(), 0);
julia> c = Sample(c, Braket.Observables.X());
```

`Braket.Amplitude`

— Type`Amplitude <: Result`

Struct which represents an amplitude measurement on a `Circuit`

.

`Braket.Amplitude`

— Method`Amplitude(states) -> Amplitude`

Constructs an Amplitude measurement of `states`

.

`states`

may be one of:

- A
`Vector{String}`

- A
`String`

All elements of `states`

must be `'0'`

or `'1'`

.

`Braket.Amplitude`

— Method`Amplitude(c::Circuit, states) -> Circuit`

Constructs an `Amplitude`

measurement of `states`

and adds it as a result to `Circuit`

`c`

.

`states`

may be of type:

`Vector{String}`

`String`

All elements of `states`

must be `'0'`

or `'1'`

.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:3));
julia> c = Amplitude(c, "0000");
```

`Braket.Probability`

— Type`Probability <: Result`

Struct which represents a probability measurement on a `Circuit`

.

`Braket.Probability`

— Method`Braket.Probability`

— Method```
Probability(c::Circuit, targets) -> Circuit
Probability(c::Circuit) -> Circuit
```

Constructs a `Probability`

measurement on qubits `targets`

and adds it as a result to `Circuit`

`c`

.

`targets`

may be one of:

- A
`QubitSet`

- A
`Vector`

of`Int`

s and/or`Qubit`

s - An
`Int`

or`Qubit`

- Absent, in which case the measurement will be applied to all qubits of
`c`

.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:3));
julia> c = Probability(c, 2);
```

`Braket.DensityMatrix`

— Type`DensityMatrix <: Result`

Struct which represents a densitymatrix measurement on a `Circuit`

.

`Braket.DensityMatrix`

— Method`Braket.DensityMatrix`

— Method`DensityMatrix(c::Circuit, targets) -> Circuit`

Constructs a `DensityMatrix`

measurement on qubits `targets`

and adds it as a result to `Circuit`

`c`

.

`targets`

may be one of:

- A
`QubitSet`

- A
`Vector`

of`Int`

s and/or`Qubit`

s - An
`Int`

or`Qubit`

- Absent, in which case the measurement will be applied to all qubits of
`c`

.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:3));
julia> c = DensityMatrix(c, 2);
```

`Braket.StateVector`

— Type`StateVector <: Result`

Struct which represents a state vector measurement on a `Circuit`

.

`Braket.StateVector`

— Method`StateVector(c::Circuit) -> Circuit`

Constructs a `StateVector`

measurement on all qubits of `c`

and adds it as a result to `Circuit`

`c`

.

**Examples**

```
julia> c = Circuit();
julia> c = H(c, collect(0:3));
julia> c = StateVector(c);
```