private void CalculateSubsystemState(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(DiscardedQubitsBox.Text)) { return; } StateOperator state = StateOperator.FromQuantumState(Layer.GetSystemState()); List <int> discardedQubits = new List <int>(); string qubits = DiscardedQubitsBox.Text.Replace(",", ""); for (int i = 0; i < qubits.Length; i++) { discardedQubits.Add(Convert.ToInt32(qubits[i] - 48)); } SubState = state.PartialTrace(discardedQubits); SubsystemState.ResizeGrid(SubState.RowDimension, SubState.ColumnDimension); for (int i = 0; i < SubState.RowDimension; i++) { for (int j = 0; j < SubState.ColumnDimension; j++) { SubsystemState[i, j] = ComplexParser.ToString(SubState[i, j], 4); } } SubsystemStateGrid.Visibility = Visibility.Visible; if (SubState.Size == 1) { ExamineSubsystemButton.IsEnabled = false; } }
protected override void OnInitialized(EventArgs e) { BlochSphere bloch = new BlochSphere(CircuitCell.CellSize); bloch.Recalculate(Qubit.BlochVector()); bloch.HorizontalAlignment = HorizontalAlignment.Left; Sphere.Children.Add(bloch); X.Content = ComplexParser.ToString(bloch.X, 4); Y.Content = ComplexParser.ToString(bloch.Y, 4); Z.Content = ComplexParser.ToString(bloch.Z, 4); Radius.Content = ComplexParser.ToString(bloch.Radius, 4); Longtitude.Content = ComplexParser.ToString(bloch.Longtitude, 4); Colatitude.Content = ComplexParser.ToString(bloch.Colatitude, 4); DensityMatrix.ResizeGrid(2, 2); DensityMatrix.HorizontalAlignment = HorizontalAlignment.Center; for (int i = 0; i < Qubit.StateOperator.RowDimension; i++) { for (int j = 0; j < Qubit.StateOperator.RowDimension; j++) { DensityMatrix[i, j] = ComplexParser.ToString(Qubit.StateOperator[i, j], 4); } } base.OnInitialized(e); }
private void InitializeWithStateOperator() { Qubits.Items.Add(StateOperator.Size); Qubits.SelectedIndex = 0; CCNR.IsChecked = true; Schmidt.IsEnabled = false; DensityMatrix.IsChecked = true; DensityMatrix.IsEnabled = StateMatrix.IsEnabled = false; Qubits.IsEnabled = false; //ResizeDefinitionMatrix(); int size = (int)Math.Pow(2, Bipartition.SystemSize); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { MatrixDefinition[i, j] = ComplexParser.ToString(StateOperator[i, j], 2); } } MatrixDefinition.IsEnabled = false; }
private void InitializeWithStateVector() { Qubits.Items.Add(State.Size); Qubits.SelectedIndex = 0; Schmidt.IsChecked = true; StateMatrix.IsChecked = true; DensityMatrix.IsEnabled = StateMatrix.IsEnabled = false; Qubits.IsEnabled = false; //ResizeDefinitionMatrix(); /* * for (int i = 0; i < Bipartition.DimensionA; i++) * for (int j = 0; j < Bipartition.DimensionB; j++) * MatrixDefinition[i, j] = ComplexParser.ToString(State[i * Bipartition.DimensionB + j], 2); */ for (int i = 0; i < MatrixDefinition.Rows; i++) { for (int j = 0; j < MatrixDefinition.Columns; j++) { MatrixDefinition[i, j] = ComplexParser.ToString(State[i * MatrixDefinition.Columns + j], 2); } } MatrixDefinition.IsEnabled = false; }
protected override void OnInitialized(EventArgs e) { if (Reg.Size == 1) { Qubits.Content = "Qubits: " + FirstQubitIndex.ToString(); } else { Qubits.Content = "Qubits: " + FirstQubitIndex.ToString() + "-" + (FirstQubitIndex + Reg.Size - 1).ToString(); } int matrixRows, matrixCols; if (Reg.Size % 2 == 0) { matrixRows = matrixCols = (int)Math.Pow(2, Reg.Size / 2); } else { matrixRows = (int)Math.Pow(2, (Reg.Size - 1) / 2); matrixCols = (int)Math.Pow(2, (Reg.Size + 1) / 2); } StateMatrix.ResizeGrid(matrixRows, matrixCols); for (int i = 0; i < matrixRows; i++) { for (int j = 0; j < matrixCols; j++) { StateMatrix[i, j] = ComplexParser.ToString(Reg.Amplitude(i * matrixCols + j), 4).ToString(); } } if (Reg.Size == 1) { Examine.IsEnabled = false; } base.OnInitialized(e); }