AssertionParsing.hpp

Contains classes and functions for parsing and validating assertions in the test files.

namespace mqt
namespace debugger

Enums

enum class AssertionType : uint8_t

Represents the type of an assertion.

Values:

enumerator Entanglement

Asserts that the target qubits are entangled.

enumerator Superposition

Asserts that the target qubits are in superposition.

enumerator StatevectorEquality

Asserts that the target qubits are equal to a given statevector.

enumerator CircuitEquality

Asserts that the target qubits are equal to the state produced by a given circuit.

class Assertion
#include <AssertionParsing.hpp>

Represents an assertion.

Provides a base class to be extended by the different types of assertions.

Subclassed by mqt::debugger::EntanglementAssertion, mqt::debugger::EqualityAssertion, mqt::debugger::SuperpositionAssertion

Public Functions

explicit Assertion(std::vector<std::string> targetQubits, AssertionType type)

Constructs a new Assertion with the given target qubits and type.

Parameters:
  • targetQubits – The target qubits of the assertion.

  • type – The type of the assertion.

AssertionType getType() const

Gets the type of the assertion.

Returns:

The type of the assertion.

const std::vector<std::string> &getTargetQubits() const

Gets the target qubits of the assertion.

Returns:

The target qubits of the assertion.

virtual ~Assertion() = default

Destructor for the Assertion class.

void setTargetQubits(std::vector<std::string> newTargetQubits)

Sets the target qubits of the assertion.

Parameters:

newTargetQubits – The new target qubits of the assertion.

inline virtual void validate()

Validates the assertion and throws an exception, if it is invalid.

virtual bool implies(const Assertion &other) const = 0

Checks whether this assertion also implies another given assertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

Private Members

std::vector<std::string> targetQubits

The target qubits of the assertion.

AssertionType type

The type of the assertion.

class CircuitEqualityAssertion : public mqt::debugger::EqualityAssertion
#include <AssertionParsing.hpp>

Represents an equality assertion that the target qubits are equal to the state produced by a given circuit.

Public Functions

CircuitEqualityAssertion(std::string circuitCode, double similarityThreshold, std::vector<std::string> targetQubits)

Constructs a new CircuitEqualityAssertion with the given circuit code, similarity threshold, and target qubits.

Parameters:
  • circuitCode – The code of the circuit that the target qubits are compared to.

  • similarityThreshold – The threshold for the similarity of the target qubits to the expected state.

  • targetQubits – The target qubits of the assertion.

const std::string &getCircuitCode() const

Gets the code of the circuit that the target qubits are compared to.

Returns:

The code of the circuit that the target qubits are compared to.

virtual bool implies(const Assertion &other) const override

Checks whether this assertion also implies another given assertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

Private Members

std::string circuitCode

The code of the circuit that the target qubits are compared to.

class EntanglementAssertion : public mqt::debugger::Assertion
#include <AssertionParsing.hpp>

Represents an assertion that the target qubits are entangled.

Public Functions

explicit EntanglementAssertion(std::vector<std::string> targetQubits)

Constructs a new EntanglementAssertion with the given target qubits.

Parameters:

targetQubits – The target qubits of the assertion.

virtual bool implies(const Assertion &other) const override

Checks whether this assertion also implies another given assertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

class EqualityAssertion : public mqt::debugger::Assertion
#include <AssertionParsing.hpp>

Represents an assertion that the target qubits are equal to a given state representation.

Subclassed by mqt::debugger::CircuitEqualityAssertion, mqt::debugger::StatevectorEqualityAssertion

Public Functions

EqualityAssertion(double similarityThreshold, std::vector<std::string> targetQubits, AssertionType type)

Constructs a new EqualityAssertion with the given similarity threshold, target qubits, and type.

Parameters:
  • similarityThreshold – The threshold for the similarity of the target qubits to the expected state.

  • targetQubits – The target qubits of the assertion.

  • type – The type of the assertion.

double getSimilarityThreshold() const

Gets the similarity threshold of the assertion.

Returns:

The similarity threshold of the assertion.

virtual void validate() override

Validates the assertion and throws an exception, if it is invalid.

Checks, whether the similarity threshold is inside the range of [0, 1].

Private Members

double similarityThreshold

The threshold for the similarity of the target qubits to the statevector or circuit.

class StatevectorEqualityAssertion : public mqt::debugger::EqualityAssertion
#include <AssertionParsing.hpp>

Represents an equality assertion that the target qubits are equal to a given statevector.

Public Functions

StatevectorEqualityAssertion(Statevector targetStatevector, double similarityThreshold, std::vector<std::string> targetQubits)

Constructs a new StatevectorEqualityAssertion with the given target statevector, similarity threshold, and target qubits.

Parameters:
  • targetStatevector – The target statevector that the target qubits are compared to.

  • similarityThreshold – The threshold for the similarity of the target qubits to the expected state.

  • targetQubits – The target qubits of the assertion.

const Statevector &getTargetStatevector() const

Gets the target statevector of the assertion.

Returns:

The target statevector of the assertion.

~StatevectorEqualityAssertion() override

Destructor for the StatevectorEqualityAssertion class.

Deletes the memory block allocated to the target statevector.

virtual void validate() override

Validates the assertion and throws an exception, if it is invalid.

Checks, whether the target statevector is valid.

virtual bool implies(const Assertion &other) const override

Checks whether this assertion also implies another given assertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

Private Functions

bool implies(const StatevectorEqualityAssertion &other) const

Checks whether this assertion also implies another given StatevectorEqualityAssertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

bool implies(const SuperpositionAssertion &other) const

Checks whether this assertion also implies another given SuperpositionAssertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

bool implies(const EntanglementAssertion &other) const

Checks whether this assertion also implies another given EntanglementAssertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.

Private Members

Statevector targetStatevector

The target statevector that the target qubits are compared to.

The memory block allocated to the state vector is owned by this object.

class SuperpositionAssertion : public mqt::debugger::Assertion
#include <AssertionParsing.hpp>

Represents an assertion that the target qubits are in superposition.

Public Functions

explicit SuperpositionAssertion(std::vector<std::string> targetQubits)

Constructs a new SuperpositionAssertion with the given target qubits.

Parameters:

targetQubits – The target qubits of the assertion.

virtual bool implies(const Assertion &other) const override

Checks whether this assertion also implies another given assertion.

Parameters:

other – The other assertion to check.

Returns:

True if this assertion implies the other assertion, false otherwise.