Skip to content

Commit

Permalink
Resource estimator visualization (#480)
Browse files Browse the repository at this point in the history
Resource Estimator Visualization Library

Co-authored-by: Katy McClintic <kamcclin@microsoft.com>
Co-authored-by: Katy McClintic <8239561+katymccl@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent 7af5ae4 commit a6d8110
Show file tree
Hide file tree
Showing 41 changed files with 39,516 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ htmlcov/

# Other
*.ini
*.json
dist/
temp/
.[v]env/
Expand Down
8 changes: 8 additions & 0 deletions visualization/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Node Modules
react-lib/node_modules/

# Test Coverage
coverage/

# Test Results
TestResults/
17 changes: 17 additions & 0 deletions visualization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Visualization

This folder includes the visualization project.

- react-lib: source code for the visualization components and D3 integration.
- js-lib: wrapper JavaScript library which packages the visualization components into a consumable JavaScript package by clients.

Refer to **build** folder to build and package the js-lib and react-lib.

For react-build project:

```
- npm run build // builds react-lib
- npm run tests //runs all tests and code coverage
- npm run testsonly //excludes code coverage
- npm run updatetests //updates test snapshots and runs tests with no coverage
```
14 changes: 14 additions & 0 deletions visualization/build/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Visualization Library Build Process

## Local Dev

Run `build-all-local.sh` script from the build folder.

## ADO pipeline flow for CI/CD

> [_microsoft.visualization_](https://ms-quantum.visualstudio.com/Quantum%20Program/_build?definitionId=789&_a=summary)
The build pipeline is composed of:

- `visualization-lib.yml`
- `build-jslib.sh`
59 changes: 59 additions & 0 deletions visualization/build/build-all-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Use flag buildJsLibOnly to only build js-lib

if [ "$1" == "buildJsLibOnly" ]; then
cd ../js-lib
npm link react quantum-visualization
if [ $? -eq 0 ]; then
echo 'Successfully linked react and quantum-visualization'
fi

npm run lint

npm run sortpackagejson || true

npm run build
if [ $? -eq 0 ]; then
echo 'Successfully built js-lib'
exit 0
fi

else

cd ../react-lib
npm install
if [ $? -eq 0 ]; then
echo 'Successfully installed react-lib'
fi

npm run sortpackagejson || true

npm run build
if [ $? -eq 0 ]; then
echo 'Successfully built react-lib'
fi
npm link
if [ $? -eq 0 ]; then
echo 'Successfully created link" react-lib'
fi
cd node_modules/react
npm link
if [ $? -eq 0 ]; then
echo 'Successfully created link: node_modules/react'
fi
cd ../../../js-lib
npm link react quantum-visualization
if [ $? -eq 0 ]; then
echo 'Successfully linked react and quantum-visualization to js-lib.'
fi

npm run sortpackagejson || true

npm run build
if [ $? -eq 0 ]; then
echo 'Successfully built js-lib'
fi
echo 'Successfully built js-lib and dependencies.'
echo 'js-lib located in dist/index.js.'
exit 0
fi
63 changes: 63 additions & 0 deletions visualization/build/build-jslib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# assume working directory to be "visualization/build"

cd ../react-lib
npm install
if [ $? -ne 0 ]; then
echo 'Failed to install: react-lib'
exit 1
else
echo 'Successfully install: react-lib'
fi

npm run lint

npm run sortpackagejson || true

npm run build:prod
if [ $? -ne 0 ]; then
echo 'Failed to build: react-lib'
exit 1
else
echo 'Successfully build: react-lib'
fi

npm link
if [ $? -ne 0 ]; then
echo 'Failed to create link: react-lib'
exit 1
else
echo 'Successfully created link: react-lib'
fi

cd node_modules/react
npm link
if [ $? -ne 0 ]; then
echo 'Failed to create link: node_modules/react'
exit 1
else
echo 'Successfully created link: node_modules/react'
fi

cd ../../../js-lib
npm link react quantum-visualization
if [ $? -ne 0 ]; then
echo 'Failed to link react and quantum-visualization to js-lib.'
exit 1
else
echo 'Successfully linked react and quantum-visualization to js-lib'
fi

npm run sortpackagejson || true

npm run build:prod
if [ $? -ne 0 ]; then
echo 'Failed to build js-lib'
exit 1
else
echo 'Successfully built js-lib'
fi

echo 'Successfully built js-lib and dependencies.'
echo 'js-lib to be published to microsoft-visualization/index.js artifact.'
exit 0
89 changes: 89 additions & 0 deletions visualization/build/visualization-lib-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Builds react-lib, js-lib and links the packages.
resources:
- repo: self
clean: true

# Trigger whenever a PR is submitted
pr:
branches:
include:
- main
paths:
include:
- visualization

variables:
rootDirectory: visualization
project: $(rootDirectory)/react-lib
jslib: $(rootDirectory)/js-lib
reactnodemodules: node_modules/react
projectname: quantum-visualization
outputDirectory: $(Agent.BuildDirectory)/output
tests: $(project)/TestResults

stages:
- stage: Build_Visualization_Library
pool:
vmImage: "windows-latest"
jobs:
- job: Build_Test_Link_Publish
steps:
- task: UseDotNet@2
inputs:
version: "3.1.x"

- task: NodeTool@0
inputs:
versionSpec: "16.x"

- task: Bash@3
displayName: "Build js-lib and dependencies"
inputs:
targetType: "filePath"
filePath: "$(rootDirectory)/build/build-jslib.sh"
failOnStderr: true
workingDirectory: "$(rootDirectory)/build/"

# - task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
# displayName: 'Signing'
# inputs:
# ConnectedServiceName: CodeSign
# FolderPath: "$(jslib)/dist/"
# Pattern: "*.js"
# CertificateId: 100040160
# OpusName: "Microsoft Quantum Development Kit"
# OpusInfo: "https://www.microsoft.com/quantum"
# SessionTimeout: 120

- task: CopyFiles@2
inputs:
SourceFolder: "$(jslib)/dist/"
Contents: "**"
TargetFolder: "$(outputDirectory)"
displayName: "Copy build artifacts to output directory"

- task: Npm@1
displayName: npm run tests (react-lib)
inputs:
workingDir: "$(project)"
command: "custom"
customCommand: "run testsonly"

- task: PublishTestResults@2
displayName: "Publish Test Results (react-lib)"
condition: succeededOrFailed()
inputs:
testResultsFiles: "$(tests)/test-results.xml"

- task: PublishCodeCoverageResults@1
displayName: "Publish Code Coverage Results (react-lib)"
condition: succeededOrFailed()
inputs:
codeCoverageTool: "cobertura"
summaryFileLocation: "$(project)/coverage/cobertura-coverage.xml"

- task: PublishPipelineArtifact@1
inputs:
targetPath: $(outputDirectory)"
artifactType: "pipeline"
artifactName: "microsoft-visualization"
86 changes: 86 additions & 0 deletions visualization/build/visualization-lib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Builds react-lib, js-lib and links the packages.
resources:
- repo: self
clean: true

# Trigger whenever a commit occurs in these branches
trigger:
branches:
include:
- main

variables:
rootDirectory: visualization
project: $(rootDirectory)/react-lib
jslib: $(rootDirectory)/js-lib
reactnodemodules: node_modules/react
projectname: quantum-visualization
outputDirectory: $(Agent.BuildDirectory)/output
tests: $(project)/TestResults

stages:
- stage: Build_Visualization_Library
pool:
vmImage: "windows-latest"
jobs:
- job: Build_Test_Link_Publish
steps:
- task: UseDotNet@2
inputs:
version: "3.1.x"

- task: NodeTool@0
inputs:
versionSpec: "16.x"

- task: Bash@3
displayName: "Build js-lib and dependencies"
inputs:
targetType: "filePath"
filePath: "$(rootDirectory)/build/build-jslib.sh"
failOnStderr: true
workingDirectory: "$(rootDirectory)/build/"

# - task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
# displayName: 'Signing'
# inputs:
# ConnectedServiceName: CodeSign
# FolderPath: "$(jslib)/dist/"
# Pattern: "*.js"
# CertificateId: 100040160
# OpusName: "Microsoft Quantum Development Kit"
# OpusInfo: "https://www.microsoft.com/quantum"
# SessionTimeout: 120

- task: CopyFiles@2
inputs:
SourceFolder: "$(jslib)/dist/"
Contents: "**"
TargetFolder: "$(outputDirectory)"
displayName: "Copy build artifacts to output directory"

- task: Npm@1
displayName: npm run tests (react-lib)
inputs:
workingDir: "$(project)"
command: "custom"
customCommand: "run testsonly"

- task: PublishTestResults@2
displayName: "Publish Test Results (react-lib)"
condition: succeededOrFailed()
inputs:
testResultsFiles: "$(tests)/test-results.xml"

- task: PublishCodeCoverageResults@1
displayName: "Publish Code Coverage Results (react-lib)"
condition: succeededOrFailed()
inputs:
codeCoverageTool: "cobertura"
summaryFileLocation: "$(project)/coverage/cobertura-coverage.xml"

- task: PublishPipelineArtifact@1
inputs:
targetPath: $(outputDirectory)"
artifactType: "pipeline"
artifactName: "microsoft-visualization"
11 changes: 11 additions & 0 deletions visualization/js-lib/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function (api) {
api.cache(true);

const presets = [ "@babel/preset-env", "@babel/preset-react" ];
const generatorOpts ={"compact" : true};

return {
presets,
generatorOpts
};
}
Loading

0 comments on commit a6d8110

Please sign in to comment.