Skip to content

Unity API Reference

All classes live in the QRG.QuantumForge.Runtime namespace (MonoBehaviour wrappers) or QRG.QuantumForge.Core namespace (native C# API).

QuantumProperty

MonoBehaviour — gives a GameObject quantum state.

Inspector Fields

FieldTypeDescription
basisBasisThe basis (ScriptableObject) defining possible states

Properties

PropertyTypeDescription
DimensionintNumber of basis values (read-only)

Predicate Creation

csharp
Predicate is_value(BasisValue value)
Predicate is_value(string valueName)
Predicate is_value(int valueIndex)
Predicate is_not_value(BasisValue value)
Predicate is_not_value(string valueName)
Predicate is_not_value(int valueIndex)

Single-Property Gates

All accept optional params Predicate[] for conditional application.

csharp
void Cycle(params Predicate[] predicates)
void Cycle(float fraction, params Predicate[] predicates)

void Shift(params Predicate[] predicates)
void Shift(float fraction, params Predicate[] predicates)

void Clock(params Predicate[] predicates)
void Clock(float fraction, params Predicate[] predicates)

void Hadamard(params Predicate[] predicates)
void Hadamard(float fraction, params Predicate[] predicates)

void InverseHadamard(params Predicate[] predicates)

void X(params Predicate[] predicates)       // alias for Shift
void X(float fraction, params Predicate[] predicates)

void Y(params Predicate[] predicates)       // qubit-only (dim=2)
void Y(float fraction, params Predicate[] predicates)

void Z(params Predicate[] predicates)       // alias for Clock
void Z(float fraction, params Predicate[] predicates)

void Reset(int currentValue)                // reset to |0⟩ from known value

Two-Property Gates (Static)

csharp
static void Swap(QuantumProperty prop1, QuantumProperty prop2, params Predicate[] predicates)

static void ISwap(QuantumProperty prop1, QuantumProperty prop2)
static void ISwap(QuantumProperty prop1, QuantumProperty prop2, float fraction)
static void ISwap(QuantumProperty prop1, QuantumProperty prop2, float fraction, params Predicate[] predicates)

static void NCycle(QuantumProperty prop1, QuantumProperty prop2)

Phase Rotation (Static)

csharp
static void PhaseRotate(float angle, params Predicate[] predicates)

Measurement (Static)

csharp
static int[] Measure(params QuantumProperty[] properties)
static int[] MeasureProperties(params QuantumProperty[] properties)  // alias

static int Measure(params Predicate[] predicates)         // stochastic projection
static int MeasurePredicate(params Predicate[] predicates) // alias

Returns an array of measured basis value indices. Entangled partners update automatically.

Analysis (Static)

csharp
static BasisProbability[] Probabilities(params QuantumProperty[] properties)
static Complex[,] ReducedDensityMatrix(params QuantumProperty[] properties)
static float[] MutualInformation(params QuantumProperty[] properties)
static float[,] CorrelationMatrix(params QuantumProperty[] properties)

BasisProbability

csharp
public struct BasisProbability
{
    public float Probability;
    public BasisValue[] BasisValues;
}

Predicate

Conditions for controlled quantum operations.

csharp
[Serializable]
public struct Predicate
{
    public QuantumProperty property;
    public BasisValue value;
    public bool is_equal;  // true = "is this value", false = "is NOT this value"
}

Create via convenience methods on QuantumProperty:

csharp
var pred = myProp.is_value("rock");      // true when property is "rock"
var pred = myProp.is_not_value(0);       // true when property is NOT index 0

Basis

ScriptableObject — defines the possible states of a quantum property.

Create via: Assets > Create > Quantum > Basis

FieldTypeDescription
valuesList<BasisValue>The list of basis values
DimensionintNumber of values (read-only)

BasisValue

csharp
[Serializable]
public struct BasisValue : IEquatable<BasisValue>
{
    public string Name;
}

Actions

All actions implement IQuantumAction and are MonoBehaviours you can attach to GameObjects and wire to Unity Events.

IQuantumAction Interface

csharp
public interface IQuantumAction
{
    Predicate[] Predicates { get; set; }
    QuantumProperty[] TargetProperties { get; set; }
    void apply();
}

Action Components

ComponentTargetsParametersDescription
Hadamard1+fraction (0–1)Creates equal superposition
Cycle1+fractionCyclic permutation (NOT for dim=2)
Shift1+fractionGeneralized bit-flip
Clock1+fractionPhase rotation (Z-rotation)
InverseHadamard1+Adjoint of Hadamard
X1+fractionPauli X (alias for Shift)
Y1+fractionPauli Y (dim=2 only)
Z1+fractionPauli Z (alias for Clock)
ISwapexactly 2fractionEntanglement gate
Swapexactly 2State exchange
NCycleexactly 2Entangling operation
PhaseRotatevia predicatesRadians (0–2π)Phase rotation on predicate-matched states
MeasureProperties1+Collapse and fire Unity Events
MeasurePredicatesvia predicatesProjective predicate measurement

MeasureProperties Events

csharp
UnityEvent OnMeasure                      // fires after measurement
QuantumPropertyEvent OnMeasureQuantumProperty  // fires per property with result
int[] LastResult { get; }                 // most recent outcomes

MeasurePredicates Events

csharp
UnityEvent OnMeasure                      // fires after measurement
MeasurePredicateEvent OnMeasurePredicates  // fires with bool (true if satisfied)
int LastResult { get; }                   // 0 or 1

Trackers

MonoBehaviours that monitor quantum state. All have a continuous field — when enabled, they update every frame. When disabled, call their update methods manually.

TrackerOutputUse Case
ProbabilityTrackerBasisProbability[]Show probability distribution
EntanglementTrackerfloat[]Quantify entanglement (mutual information)
CorrelationTrackerfloat[,]Measurement correlations (Pearson coefficient)
PhaseTrackerfloat[,]Relative phases between states
ReducedDensityMatrixTrackerComplex[,]Full density matrix

Common Fields

FieldTypeDefaultDescription
quantumPropertiesQuantumProperty[]auto-detectedProperties to track
continuousbooltrueAuto-update every frame

All trackers auto-populate quantumProperties from the attached QuantumProperty component if left empty.


Core API

For advanced users who need direct C# access without MonoBehaviours.

Namespace: QRG.QuantumForge.Core

NativeQuantumProperty

csharp
var prop = new NativeQuantumProperty(dimension: 2);         // starts in superposition
var prop = new NativeQuantumProperty(dimension: 2, initial: 0); // starts in |0⟩
prop.Dispose(); // cleanup when done

QuantumForge Static Methods

Same gate operations as QuantumProperty but operating on NativeQuantumProperty:

csharp
QuantumForge.Cycle(prop, fraction, predicates);
QuantumForge.Hadamard(prop, predicates);
QuantumForge.ISwap(prop1, prop2, fraction, predicates);
QuantumForge.PhaseRotate(angle, predicates);

int[] results = QuantumForge.Measure(prop1, prop2);
BasisProbability[] probs = QuantumForge.Probabilities(prop);
Complex[,] rdm = QuantumForge.ReducedDensityMatrix(prop1, prop2);

Error Codes

csharp
public enum QForgeError
{
    QFORGE_ERR_NONE,
    QFORGE_ERR_NULL_POINTER,
    QFORGE_ERR_INVALID_ARGUMENT,
    QFORGE_ERR_BUFFER_TOO_SMALL,
    QFORGE_ERR_TARGET_CONTROL_OVERLAP,
    QFORGE_ERR_INCOMPATIBLE_DIMENSIONS,
    QFORGE_ERR_BAD_DIMENSION,
    QFORGE_ERR_BAD_QUDIT_NUMBER,
    QFORGE_ERR_OUTPUT_BUFFER_SIZE_NOT_EQUAL_TO_PERMUTATIONS,
    QFORGE_ERR_MAX_STATE_SIZE_EXCEEDED
}

Powered by Quantum Forge