pub struct Circuit { /* private fields */ }Expand description
A quantum circuit builder that constructs a tensor network representing a quantum circuit.
Implementations§
Source§impl Circuit
impl Circuit
Sourcepub fn num_qubits(&self) -> usize
pub fn num_qubits(&self) -> usize
Returns the total number of qubits allocated in this circuit.
§Examples
let mut circuit = Circuit::default();
let q1 = circuit.allocate_register(2);
let q2 = circuit.allocate_register(3);
assert_eq!(circuit.num_qubits(), 5);Sourcepub fn allocate_register<'a>(&mut self, size: usize) -> QuantumRegister<'a>
pub fn allocate_register<'a>(&mut self, size: usize) -> QuantumRegister<'a>
Allocates a new quantum register. The qubits are initialized in the |0> state.
Sourcepub fn append_gate(&mut self, gate: TensorData, indices: &[Qubit<'_>])
pub fn append_gate(&mut self, gate: TensorData, indices: &[Qubit<'_>])
Appends a gate to the circuit on the specified qubits.
Sourcepub fn into_amplitude_network(self, bitstring: &str) -> (Tensor, Permutor)
pub fn into_amplitude_network(self, bitstring: &str) -> (Tensor, Permutor)
Converts the circuit to a tensor network that computes the amplitude for the given bitstring.
The bitstring can also contain wildcards *, in which case the tensor leg
corresponding to this qubit is left open. For every wildcard, the output
tensor will be doubled in size. In the extreme case where there’s only
wildcards, the full statevector will be computed.
Since the final tensor can end up with arbitrary permutation, a Permutor
is returned that can transpose the final tensor after contraction to the
natural order, i.e., sorted by increasing qubit number. If the bitstring
contains no wildcards, the final result is a scalar and the permutator can be
ignored.
Sourcepub fn into_statevector_network(self) -> (Tensor, Permutor)
pub fn into_statevector_network(self) -> (Tensor, Permutor)
Converts the circuit to a tensor network that computes the full statevector.
Since the final tensor can end up with arbitrary permutation, a Permutor
is returned that can transpose the final tensor after contraction to the
natural order, i.e., sorted by increasing qubit number.
Sourcepub fn into_expectation_value_network(self) -> Tensor
pub fn into_expectation_value_network(self) -> Tensor
Converts the circuit to a tensor network that computes the expectation value
with respect to standard observables (Z) on all qubits.
The tensor network is roughly twice the size of the circuit, as it needs to compute the adjoint of the circuit as well.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Circuit
impl RefUnwindSafe for Circuit
impl Send for Circuit
impl Sync for Circuit
impl Unpin for Circuit
impl UnwindSafe for Circuit
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specialization§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more